)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Platform: WinForms |
Control: GridGroupingControl |
Published Date: March 21, 2016 |
Last Revised Date: December 23, 2019

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

Samples:

C#: HeaderCaption_CS

VB: HeaderCaption_VB

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

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon