How to create a new column in WinForms GridListControl?
Add a new column
To add a new column into WinForms GridListControl, the ‘QueryColCount’ event can be used. `QueryCellInfo` event is used for assigning the cell values for the newly added columns.
C#:
this.gridListControl1.Grid.QueryColCount+=Grid_QueryColCount; this.gridListControl1.Grid.QueryCellInfo+=Grid_QueryCellInfo; private void Grid_QueryColCount(object sender, GridRowColCountEventArgs e) { e.Count = 3; e.Handled = true; } private void Grid_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) { if (e.RowIndex > 0 && e.ColIndex == 3) { e.Style.CellValue = "testc"; } if (e.RowIndex == 0 && e.ColIndex==3) { e.Style.CellValue = "Col name"; } }
VB:
Private Me.gridListControl1.Grid.QueryColCount+= AddressOf Grid_QueryColCount Private Me.gridListControl1.Grid.QueryCellInfo+= AddressOf Grid_QueryCellInfo Private Sub Grid_QueryColCount(ByVal sender As Object, ByVal e As GridRowColCountEventArgs) e.Count = 3 e.Handled = True End Sub Private Sub Grid_QueryCellInfo(ByVal sender As Object, ByVal e As GridQueryCellInfoEventArgs) If e.RowIndex > 0 AndAlso e.ColIndex = 3 Then e.Style.CellValue = "testc" End If If e.RowIndex = 0 AndAlso e.ColIndex=3 Then e.Style.CellValue = "Col name" End If End Sub
Samples:
C#: Add a new column
VB: Add a new column
Conclusion
I hope you enjoyed learning about how to create a new column in WinForms GridListControl.
You can refer to our WinForms GridListControl’s feature tour page to know about its other groundbreaking feature representations.
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 GridListControl and other WinForms components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!