Category / Section
How to replace the plus or minus cell of the group caption row with an empty cell when there is only one record in that group in WinForms GridGroupingControl?
2 mins read
Hide the plus or minus symbol
By default, the GridGroupingControl shows the plus/minus symbol for all the groups whether the group contains only one record or many records. When you want to hide the plus/minus symbol for the groups that have only one record, then use the following solution.
Solution:
In order to replace the Plus/Minus PushButton of the caption row, you need to handle the QueryCellStyleInfo event. In the event handler, change the PushButton CellType to Static CellType and expand the group that has only one record.
C#
//Hooks the QueryCellStyleInfo event in the Form_Load. this.gridGroupingControl1.QueryCellStyleInfo += gridGroupingControl1_QueryCellStyleInfo; void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e) { //Gets the display element. Element el = e.TableCellIdentity.DisplayElement; //Checks whether the element is in the Caption row. if(el.Kind == DisplayElementKind.Caption) { //Checks whether the Group has only one record. if(el.ParentGroup.FilteredRecords.Count == 1) { if(e.Style.CellType == "PushButton") { //Changes the PushButton to the Static cell type. e.Style.CellType = "Static"; e.Style.BackColor = System.Drawing.SystemColors.Control; el.ParentGroup.SetExpanded(true, true, true); //Disables Click. e.Style.Clickable = false; e.Style.Enabled = false; } } } }
VB
'Hooks the QueryCellStyleInfo event in the Form_Load. Private Me.gridGroupingControl1.QueryCellStyleInfo += AddressOf gridGroupingControl1_QueryCellStyleInfo Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs) 'Gets the display element. Dim el As Element = e.TableCellIdentity.DisplayElement 'Checks whether the element is in the Caption row. If el.Kind = DisplayElementKind.Caption Then 'Check whether the Group has only one record. If el.ParentGroup.FilteredRecords.Count = 1 Then If e.Style.CellType Is "PushButton" Then 'Changes the PushButton to the Static cell type. e.Style.CellType = "Static" e.Style.BackColor = System.Drawing.SystemColors.Control el.ParentGroup.SetExpanded(True, True, True) 'Disables Click. e.Style.Clickable = False e.Style.Enabled = False End If End If End If End Sub
The following screenshot displays the plus/minus symbol hidden.
Figure 1: Plus/Minus symbols hidden