Articles in this section

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

Header row


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

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

Using NumberedRowHeaders

C#

this.gridGroupingControl1.Appearance.AnyHeaderCell.CellType = GridCellTypeName.Header;
this.gridGroupingControl1.TableModel.Options.NumberedRowHeaders = true;
VB
Me.gridGroupingControl1.Appearance.AnyHeaderCell.CellType = GridCellTypeName.Header
Me.gridGroupingControl1.TableModel.Options.NumberedRowHeaders = True
Using PrepareViewStyleInfo event

C#
//To display the Numbered row header
this.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:
' To display the Numbered row header
AddHandler gridGroupingControl1.TableControl.PrepareViewStyleInfo, AddressOf 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 = DisplayElementKind.Record Then

        Dim record As Record = gridGroupingControl1.Table.Records(0)
        Dim firstIndex As Integer = record.GetRowIndex()

        If e.RowIndex >= 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
The screenshot below illustrates the caption row headers in GridGroupingControl

Applied formatting to header row in winforms gridgroupingcontrol

Samples:

C#: HeaderCaption_CS

VB: HeaderCaption_VB

 

Reference Link: Appearance and Formatting 

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