The width of a column can be changed using either the Width property or the GetFittedWidth method. You can also retrieve the value necessary to display the entire contents of a cell using its GetFittedWidth method.
To change the width of a column the following code can be used:
VB.NET | Copy Code |
---|---|
GridControl1.Columns( "ShipCountry" ).Width = 40 |
C# | Copy Code |
---|---|
gridControl1.Columns[ "ShipCountry" ].Width = 40; |
If you want to change the width of each column in the grid, you will need to do a "for each" to iterate through each one of the grid's columns. A common use would be to set the width of each column to its fitted width (the width necessary to display the entire content of the column) using the GetFittedWidth method. For example:
VB.NET | Copy Code |
---|---|
|
C# | Copy Code |
---|---|
|
To make sure that the width of the columns stays to their fitted widths even if, for example, the length of one of the column's cell's value changes, you will need to call the GetFittedWidth method in each cell's ValueChanged event. For example:
VB.NET | Copy Code |
---|---|
|
C# | Copy Code |
---|---|
|
If the DataRowTemplate changes while the DataSource property is set, the changes will not automatically be reflected in the grid. In order for the modifications to be applied, the data source must be reassigned to the DataSource property.
If you want to set various properties of the DataRowTemplate when you populate your grid (set the DataSource property), then this will need to be done between calls to the grid's BeginInit and EndInit methods.
If you are providing data manually, then you can set the values of the DataRowTemplate after you have added columns to the grid.