Category / Section
How to set a column width in WinForms GridListControl?
1 min read
Column width
To set the width of a GridListControl’s particular column, ColWidths property or QueryColWidth event can be used.
Using ColWidths property
C#
//To change the width of the columns.
this.gridListControl1.Grid.Model.ColWidths["CategoryName"] = 125;
this.gridListControl1.Grid.Model.ColWidths["Description"] = 125;
VB
'To change the width of the columns.
Me.gridListControl1.Grid.Model.ColWidths("CategoryName") = 125
Me.gridListControl1.Grid.Model.ColWidths("Description") = 125
Using QueryColWidth event
The column width can be set by setting the Size property. The e.Handled property should be set to true.
C#
//Event subscriptions.
this.gridListControl1.Grid.QueryColWidth += Grid_QueryColWidth;
//Event Customization
private void Grid_QueryColWidth(object sender, GridRowColSizeEventArgs e)
{
if (e.Index == 1 || e.Index == 2)
{
e.Size = 125;
e.Handled = true;
}
}
VB
'Event subscriptions.
AddHandler Me.gridListControl1.Grid.QueryColWidth, AddressOf Grid_QueryColWidth
'Event Customization
Private Sub Grid_QueryColWidth(ByVal sender As Object, ByVal e As GridRowColSizeEventArgs)
If e.Index = 1 OrElse e.Index = 2 Then
e.Size = 125
e.Handled = True
End If
End Sub
Column Width Screenshot as shown below