Category / Section
How to customize the record plus or minus icon in WinForms GridGroupingControl?
2 mins read
Customize the record plus or minus icon
To change the record (+/-) icon for expanding and collapsing, you can customize that cell in QueryCellStyleInfo event. Change the CellType of the plus/minus cell to ‘Static’. The icon image is applied to that cell by using ImageList. The current state of the record is retrieved through IsExpanded property.
C#
this.gridGroupingControl1.QueryCellStyleInfo += gridGroupingControl1_QueryCellStyleInfo; ImageList img = new ImageList(); void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e) { if (e.TableCellIdentity.TableCellType == GridTableCellType.RecordPlusMinusCell) //changing the icon in RecordPlusMinusCell when expanded { if (e.TableCellIdentity.DisplayElement.ParentRecord.IsExpanded) { e.Style.CellType = GridCellTypeName.Static; e.Style.ImageList = img; e.Style.ImageIndex = 1; } else//changing the icon in RecordPlusMinusCell when collapsed { e.Style.CellType = GridCellTypeName.Static; e.Style.ImageList = img; e.Style.ImageIndex = 0; } } }
VB
AddHandler Me.gridGroupingControl1.QueryCellStyleInfo, AddressOf gridGroupingControl1_QueryCellStyleInfo Private img As New ImageList() Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As GridTableCellStyleInfoEventArgs) If e.TableCellIdentity.TableCellType = GridTableCellType.RecordPlusMinusCell Then 'changing the icon in RecordPlusMinusCell when expanded If e.TableCellIdentity.DisplayElement.ParentRecord.IsExpanded Then e.Style.CellType = GridCellTypeName.Static e.Style.ImageList = img e.Style.ImageIndex = 1 Else 'changing the icon in RecordPlusMinusCell when collapsed e.Style.CellType = GridCellTypeName.Static e.Style.ImageList = img e.Style.ImageIndex = 0 End If End If End Sub
The following screenshot displays the modified icons for record plus/minus.
Figure 1: Modified icons for record plus/minus