Each column in the grid can contain either bound or unbound data. Binding the grid to a data source will automatically create a column for each field in the data source however it is also possible to manually add columns to the grid.
Data bound columns can be added to the grid at any time. The Linked property of each column will determine if the column has been successfully linked to a field in the data source. If the FieldName of a column matches the name of a field in the data source, the column will remain in the grid and will be populated with the field's data at run-time. In the case where a data bound column is not able to link to a field in the data source, it will remain in the grid however it will not be visible nor contain data.
VB.NET |
Copy Code |
---|---|
' Create a new column specifying the name of the field in the ' data source to which the column is to be linked Dim dataColumn As New DataBoundColumn( "ShipCountry" ) ' Add the column to the grid's list of columns. ' At this point, the value of the column's Linked property is false. GridControl1.Columns.Add( dataColumn ) ' Set the data binding GridControl1.SetDataBinding( dataSet11, "Orders" ) |
C# |
Copy Code |
---|---|
// Create a new column specifying the name of the field in the // data source to which the column is to be linked DataBoundColumn dataColumn = new DataBoundColumn( "ShipCountry" ); // Add the column to the grid's list of columns. // At this point, the value of the column's Linked property is false. gridControl1.Columns.Add( dataColumn ); // Set the data binding gridControl1.SetDataBinding( dataSet11, "Orders" ); |
Unbound columns can also be added to the grid in order to contain manually provided (unbound) data. These columns can be positioned anywhere in the grid, wether it be at the end or at the beginning of bound columns or in between them.
VB.NET |
Copy Code |
---|---|
' Create a new unbound column specifying its name as well as the type of data it will contain Dim unboundColumn As New Column( "MyColumn", GetType( String ) ) ' Add the column to the grid's list of columns. GridControl1.Columns.Add( unboundColumn ) |
C# |
Copy Code |
---|---|
// Create a new unbound column specifying its name as well as the type of data it will contain Column unboundColumn = new Column( "MyColumn", typeof( string ) ); // Add the column to the grid's list of columns. gridControl1.Columns.Add( unboundColumn ); |
Columns can be removed from the grid using the Remove method of the grid's Columns collection. For example:
VB.NET | Copy Code |
---|---|
GridControl1.Columns.Remove( gridControl1.Columns( 0 ) ) |
C# | Copy Code |
---|---|
|
Keep in mind that if your grid is bound to a data source, resetting the DataSource/ DataMember properties or calling the SetDataBinding method will have the effect of bringing back the columns that have previously been removed.