GridControl.GroupRowCollapsing Event
Occurs when a group row is about to be collapsed, allowing cancellation of the action.
Namespace: DevExpress.Xpf.Grid
Assembly: DevExpress.Xpf.Grid.v18.2.dll
Declaration
Event Data
The GroupRowCollapsing event's data class is RowAllowEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Allow | Gets or sets whether the operation is allowed. |
Handled | Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route. Inherited from RoutedEventArgs. |
OriginalSource | Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs. |
RoutedEvent | Gets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs. |
Row | Gets the processed row. Inherited from RowEventArgs. |
RowHandle | Gets the processed row’s handle. Inherited from RowEventArgs. |
Source | Gets or sets a reference to the object that raised the event. Inherited from RoutedEventArgs. |
The event data class exposes the following methods:
Method | Description |
---|---|
InvokeEventHandler(Delegate, Object) | When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation. Inherited from RoutedEventArgs. |
OnSetSource(Object) | When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes. Inherited from RoutedEventArgs. |
Remarks
The GroupRowCollapsing event is raised before a group row is collapsed by an end-user or in code, allowing you to cancel this action. The group row is identified by its handle via the RowEventArgs.RowHandle property. To prevent the group row from being collapsed, set the event parameter’s RowAllowEventArgs.Allow parameter to false.
Group rows can be collapsed recursively using the GridViewBase.CollapseFocusedRow method overload with the recursive parameter set to true. In this instance, the GroupRowCollapsing event is raised only once (for the row passed as this method’s parameter). This event isn’t raised for nesting group rows.
The GridControl.CollapseAllGroups method allows you to collapse all group rows. In this instance, the GroupRowCollapsing event is raised only once. The event parameter’s RowEventArgs.RowHandle property returns an invalid row handle (DataControlBase.InvalidRowHandle).
After the group row has been collapsed, the GridControl.GroupRowCollapsed event is raised.
To learn more, see Expanding and Collapsing Group Rows.
Example
The following example shows how to customize whether a particular group row can be collapsed.In this example, the 'Status: Invalidated' group row is prevented from being collapsed, and the full collapsing is disabled. To do this, the GroupRowCollapsing event is handled, and the event parameter's Allow property is set to false when the RowHandle property returns the 'Status: Invalidated' row's handle, or an invalid handle (this happens when all group rows are about to be collapsed).
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-prevent-group-rows-from-being-collapsed-e2024.
using System;
using System.Collections.Generic;
namespace DXExample.DemoData {
public enum InvoiceStatus { Ordered, Payed, Shipped, Delivered, Invalidated }
public class Invoice {
public int ID { get; set; }
public string ProductName { get; set; }
public double Price { get; set; }
public DateTime OrderDate { get; set; }
public double Discount { get; set; }
public bool IsUrgent { get; set; }
public InvoiceStatus Status { get; set; }
static public List<Invoice> GetData() {
List<Invoice> data = new List<Invoice>();
data.Add(new Invoice() { ID = 0, ProductName = "Tofu", IsUrgent = false,
Price = 235.54, Discount = 9.4, Status = InvoiceStatus.Invalidated,
OrderDate = new DateTime(2009, 3, 12) });
data.Add(new Invoice() { ID = 1, ProductName = "Ravioli Angelo", IsUrgent = true,
Price = 178.45, Discount = 6.1, Status = InvoiceStatus.Delivered,
OrderDate = new DateTime(2009, 2, 9) });
data.Add(new Invoice() { ID = 2, ProductName = "Geitost", IsUrgent = false,
Price = 89.98, Discount = 5.4, Status = InvoiceStatus.Payed,
OrderDate = new DateTime(2009, 4, 1) });
data.Add(new Invoice() { ID = 3, ProductName = "Chang", IsUrgent = true,
Price = 189.33, Discount = 18.2, Status = InvoiceStatus.Shipped,
OrderDate = new DateTime(2009, 5, 23) });
data.Add(new Invoice() { ID = 4, ProductName = "Inlagd Sill", IsUrgent = false,
Price = 509.10, Discount = 22.2, Status = InvoiceStatus.Ordered,
OrderDate = new DateTime(2009, 6, 30) });
data.Add(new Invoice() { ID = 5, ProductName = "Alice Mutton", IsUrgent = true,
Price = 791.18, Discount = 24.4, Status = InvoiceStatus.Invalidated,
OrderDate = new DateTime(2009, 5, 7) });
return data;
}
}
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the GroupRowCollapsing event.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.