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).
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_PreventGroupRowFromCollapsing.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 Collapsing" Height="380" Width="335">
<Grid>
<dxg:GridControl
GroupRowCollapsing="gridControl1_GroupRowCollapsing" AutoExpandAllGroups="True" 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="Descending" x:Name="colStatus" />
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView />
</dxg:GridControl.View>
</dxg:GridControl>
</Grid>
</Window>
using System.Windows;
using DevExpress.Xpf.Grid;
using DXExample.DemoData;
namespace DXGrid_PreventGroupRowFromCollapsing {
public partial class Window1 : Window {
public Window1() {
InitializeComponent();
gridControl1.ItemsSource = Invoice.GetData();
}
private void gridControl1_GroupRowCollapsing(object sender, RowAllowEventArgs e) {
if (e.Row == null || ((Invoice)e.Row).Status == InvoiceStatus.Invalidated && colStatus.GroupIndex != -1)
e.Allow = false;
}
}
}
Imports System.Windows
Imports DevExpress.Xpf.Grid
Imports DXExample.DemoData
Namespace DXGrid_PreventGroupRowFromCollapsing
Partial Public Class Window1
Inherits Window
Public Sub New()
InitializeComponent()
gridControl1.ItemsSource = Invoice.GetData()
End Sub
Private Sub gridControl1_GroupRowCollapsing(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
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