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. Image for the cookie policy date
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

Create the column header

Sometimes it is necessary to cover the Column Header across multiple columns in WinForms GridControl. 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 in WinForms GridControl

Figure 1: ColumnHeader Col0 covers two columns.

Samples:

C#: ColumnHeadercoverstwoColumn-C#.

VB: ColumnHeadercoverstwoColumn-VB.

Conclusion

I hope you enjoyed learning about how to create a Column Header to cover two columns in WinForms GridControl.

You can refer to our WinForms GridControl’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms GridControl documentation to understand how to present and manipulate data.

For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms GridControl and other WinForms components.

 

If you have any queries or require clarifications, please let us know in the comment section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

 

 

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