Articles in this section
Category / Section

How to add row numbers for the header or caption rows in a WinForms GridGroupingControl?

1 min read

Header row

To have a numbered row header in the GridGroupingControl, there are two possible ways.

  • Use of NumberedRowHeaders property.
  • Use GridRangeInfo.GetNumericLabel() in PrepareViewStyleInfo event

C#

Method1:
this.gridGroupingControl1.Appearance.AnyHeaderCell.CellType =GridCellTypeName.Header;this.gridGroupingControl1.TableModel.Options.NumberedRowHeaders =true;

 

Method2:
//To display the Numbered row headerthis.gridGroupingControl1.TableControl.PrepareViewStyleInfo += TableControl_PrepareViewStyleInfo;
 
private void TableControl_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
    GridTableCellStyleInfo style = e.Style as GridTableCellStyleInfo;
    if (style != null && style.TableCellIdentity != null && style.TableCellIdentity.DisplayElement.Kind == DisplayElementKind.Record)
    {
        Record record = this.gridGroupingControl1.Table.Records[0];
        int firstIndex = record.GetRowIndex();
        if (e.RowIndex >= this.gridGroupingControl1.TableControl.TopRowIndex && e.ColIndex == 0)
        {
            e.Style.CellType = "Header";
            e.Style.CellValue = GridRangeInfo.GetNumericLabel(e.RowIndex - firstIndex + 1);
        }
    }
}

 

VB

Method1:
Me.gridGroupingControl1.Appearance.AnyHeaderCell.CellType =GridCellTypeName.Header
Me.gridGroupingControl1.TableModel.Options.NumberedRowHeaders =True

 

Method2:
'To display the Numbered row header
Me.gridGroupingControl1.TableControl.PrepareViewStyleInfo += TableControl_PrepareViewStyleInfo
 
Private Sub TableControl_PrepareViewStyleInfo(ByVal sender As Object, ByVal e As GridPrepareViewStyleInfoEventArgs)
    Dim style As GridTableCellStyleInfo = TryCast(e.Style, GridTableCellStyleInfo)
    If style IsNot Nothing AndAlso style.TableCellIdentity IsNot Nothing AndAlso style.TableCellIdentity.DisplayElement.Kind Is DisplayElementKind.Record Then
        Dim record As Record = Me.gridGroupingControl1.Table.Records(0)
        Dim firstIndex As Integer = record.GetRowIndex()
        If e.RowIndex >= Me.gridGroupingControl1.TableControl.TopRowIndex AndAlso e.ColIndex = 0 Then
            e.Style.CellType = "Header"
            e.Style.CellValue = GridRangeInfo.GetNumericLabel(e.RowIndex - firstIndex + 1)
        End If
    End If
End Sub

 

Screenshot

Applied formatting to header row in winforms gridgroupingcontrol

Samples:

C#: HeaderCaption_CS

VB: HeaderCaption_VB

Reference link: https://help.syncfusion.com/windowsforms/gridgrouping/appearance-and-formatting

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied