Articles in this section
Category / Section

How to create a Column Header to cover two columns in WinForms GridControl?

2 mins read

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!

 

 

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