Xceed Grid for WinForms v4.3 Documentation
Adding columns

Welcome to Xceed Grid for WinForms v4.3 > Task-Based Help > Columns and cells > Adding columns

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

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" );
Once the data binding has been completed successfully and the name of the column we just added to the grid matches the name of one of the fields in the data source, the value of the column's Linked property changes to true and the its data type matches the data type of the column in the data source to which it is linked.

Unbound columns

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 );
When using the Grid Designer, the necessary unbound columns will automatically be added when the grid is bound to a data source, however unbound columns can be added by right-clicking in the body of the grid or an existing column and selecting the Add column (unbound) menu item or verb.

Removing columns

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

gridControl1.Columns.Remove( gridControl1.Columns[ 0 ] );

If you do not want to remove columns, you can render them invisible by setting the Visible property to false. 

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.