2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
Create the column headerSometimes 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
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.
This page will automatically be redirected to the sign-in page in 10 seconds.