)
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 create a Column Header to cover two columns in WinForms GridControl?

Platform: WinForms |
Control: GridControl |
Published Date: April 30, 2011 |
Last Revised Date: December 19, 2019

Create the column header

Sometimes it is necessary to cover the Column Header across multiple columns. Refer to the below code example.

C#

//Event triggered from Form_load
this.gridGroupingControl1.QueryCoveredRange += gridGroupingControl1_QueryCoveredRange;
void gridGroupingControl1_QueryCoveredRange(object sender, GridTableQueryCoveredRangeEventArgs e)
{
     GridTable table = e.Table;
     if (e.RowIndex < table.DisplayElements.Count)
     {
        Element el = table.DisplayElements[e.RowIndex];
        if (el.Kind == DisplayElementKind.ColumnHeader && el is ColumnHeaderRow)
        {
          GridTableCellStyleInfo style = table.GetTableCellStyle(e.RowIndex, e.ColIndex);
          GridTableCellStyleInfoIdentity id = style.TableCellIdentity;
          if (id.Column != null && id.Column.MappingName == "Col0")
          {
              // Covering the Col0 across 2 columns.
              e.Range = GridRangeInfo.Cells(e.RowIndex, e.ColIndex, e.RowIndex, e.ColIndex + 1);
              e.Handled = true;
          }
       }
     }
}

 

 

VB

'Event triggered from Form_load
AddHandler Me.gridGroupingControl1.QueryCoveredRange, AddressOf gridGroupingControl1_QueryCoveredRange
Private Sub gridGroupingControl1_QueryCoveredRange(ByVal sender As Object, ByVal e As GridTableQueryCoveredRangeEventArgs)
   Dim table As GridTable = e.Table
   If e.RowIndex < table.DisplayElements.Count Then
     Dim el As Element = table.DisplayElements(e.RowIndex)
     If el.Kind = DisplayElementKind.ColumnHeader AndAlso TypeOf el Is ColumnHeaderRow Then
       Dim style As GridTableCellStyleInfo = table.GetTableCellStyle(e.RowIndex, e.ColIndex)
       Dim id As GridTableCellStyleInfoIdentity = style.TableCellIdentity
       If id.Column IsNot Nothing AndAlso id.Column.MappingName = "Col0" Then
         ' Covering the Col0 across 2 columns.
         e.Range = GridRangeInfo.Cells(e.RowIndex, e.ColIndex, e.RowIndex, e.ColIndex + 1)
         e.Handled = True
       End If
     End If
   End If
End Sub

 

First column covers the two columns

Figure 1: ColumnHeader Col0 covers two columns.

Samples:

C#: ColumnHeadercoverstwoColumn-C#.

VB: ColumnHeadercoverstwoColumn-VB.

 

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