GridControl.GroupRowExpanding Event
Occurs when a group row is about to be expanded, allowing cancellation of the action.
Namespace: DevExpress.Xpf.Grid
Assembly:
DevExpress.Xpf.Grid.v20.2.dll
NuGet Packages:
DevExpress.WindowsDesktop.Wpf.Grid.Core, DevExpress.Wpf.Grid.Core
Declaration
public event RowAllowEventHandler GroupRowExpanding
Public Event GroupRowExpanding As RowAllowEventHandler
Event Data
The GroupRowExpanding 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.
|
OriginalSource |
Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class.
|
RoutedEvent |
Gets or sets the RoutedEvent associated with this RoutedEventArgs instance.
|
Row |
Gets the processed row.
|
RowHandle |
Gets the processed row’s handle.
|
Source |
Gets or sets a reference to the object that raised the event.
|
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.
|
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.
|
The GroupRowExpanding event is raised before a group row is expanded 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 expanded, set the event parameter’s RowAllowEventArgs.Allow parameter to false.
Group rows can be expanded recursively using the GridViewBase.ExpandFocusedRow method overload with the recursive parameter set to true. In this instance, the GroupRowExpanding 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.ExpandAllGroups method allows you to expand all group rows. In this instance, the GroupRowExpanding 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 expanded, the GridControl.GroupRowExpanded 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 expanded.In this example, the 'Status: Invalidated' group row is prevented from being expanded, and the full expanding is disabled. To do this, the GroupRowExpanding 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 expanded).
View Example
using System.Windows;
using DevExpress.Xpf.Grid;
using DXExample.DemoData;
namespace DXGrid_PreventGroupRowsFromExpanding {
public partial class Window1 : Window {
public Window1() {
InitializeComponent();
gridControl1.ItemsSource = Invoice.GetData();
}
private void gridControl1_GroupRowExpanding(object sender, RowAllowEventArgs e) {
if ( e.Row == null ||
((Invoice)e.Row).Status == InvoiceStatus.Invalidated &&
colStatus.GroupIndex != -1 )
e.Allow = false;
}
}
}
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;
}
}
}
<Window x:Class="DXGrid_PreventGroupRowsFromExpanding.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
Title="Preventing Groups from Expanding" Height="380" Width="335">
<Grid>
<dxg:GridControl GroupRowExpanding="gridControl1_GroupRowExpanding" Name="gridControl1">
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="ProductName" />
<dxg:GridColumn FieldName="Price" Width="60" />
<dxg:GridColumn FieldName="Discount" Width="75" />
<dxg:GridColumn FieldName="Status" GroupIndex="0" SortOrder="Ascending" x:Name="colStatus" />
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView />
</dxg:GridControl.View>
</dxg:GridControl>
</Grid>
</Window>
Imports System
Imports System.Collections.Generic
Namespace DXExample.DemoData
Public Enum InvoiceStatus
Ordered
Payed
Shipped
Delivered
Invalidated
End Enum
Public Class Invoice
Public Property ID() As Integer
Public Property ProductName() As String
Public Property Price() As Double
Public Property OrderDate() As Date
Public Property Discount() As Double
Public Property IsUrgent() As Boolean
Public Property Status() As InvoiceStatus
Public Shared Function GetData() As List(Of Invoice)
Dim data As New List(Of Invoice)()
data.Add(New Invoice() With {.ID = 0, .ProductName = "Tofu", .IsUrgent = False, .Price = 235.54, .Discount = 9.4, .Status = InvoiceStatus.Invalidated, .OrderDate = New Date(2009, 3, 12)})
data.Add(New Invoice() With {.ID = 1, .ProductName = "Ravioli Angelo", .IsUrgent = True, .Price = 178.45, .Discount = 6.1, .Status = InvoiceStatus.Delivered, .OrderDate = New Date(2009, 2, 9)})
data.Add(New Invoice() With {.ID = 2, .ProductName = "Geitost", .IsUrgent = False, .Price = 89.98, .Discount = 5.4, .Status = InvoiceStatus.Payed, .OrderDate = New Date(2009, 4, 1)})
data.Add(New Invoice() With {.ID = 3, .ProductName = "Chang", .IsUrgent = True, .Price = 189.33, .Discount = 18.2, .Status = InvoiceStatus.Shipped, .OrderDate = New Date(2009, 5, 23)})
data.Add(New Invoice() With {.ID = 4, .ProductName = "Inlagd Sill", .IsUrgent = False, .Price = 509.10, .Discount = 22.2, .Status = InvoiceStatus.Ordered, .OrderDate = New Date(2009, 6, 30)})
data.Add(New Invoice() With {.ID = 5, .ProductName = "Alice Mutton", .IsUrgent = True, .Price = 791.18, .Discount = 24.4, .Status = InvoiceStatus.Invalidated, .OrderDate = New Date(2009, 5, 7)})
Return data
End Function
End Class
End Namespace
Imports System.Windows
Imports DevExpress.Xpf.Grid
Imports DXExample.DemoData
Namespace DXGrid_PreventGroupRowsFromExpanding
Partial Public Class Window1
Inherits Window
Public Sub New()
InitializeComponent()
gridControl1.ItemsSource = Invoice.GetData()
End Sub
Private Sub gridControl1_GroupRowExpanding(ByVal sender As Object, ByVal e As RowAllowEventArgs)
If e.Row Is Nothing OrElse CType(e.Row, Invoice).Status = InvoiceStatus.Invalidated AndAlso colStatus.GroupIndex <> -1 Then
e.Allow = False
End If
End Sub
End Class
End Namespace
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the GroupRowExpanding 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.
See Also