How to create a Column Header to cover two columns in WinForms GridControl?
Create the column header
Sometimes it is necessary to cover the Column Header across multiple columns in the WinForms GridControl. Refer to the code example below.
//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;
}
}
}
}'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 SubThe
screenshot below illustrates the column header that covers two columns.

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 feature tour page to know about its other groundbreaking feature representations and WinForms GridControl documentation, and how to quickly get started for configuration specifications.
For current customers, you can check out our 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 other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!