Xceed Grid for WinForms v4.3 Documentation
What is a column?
Welcome to Xceed Grid for WinForms v4.3 > Basic Concepts > Grid elements > What is a column?

A column is a vertical arrangement of cells that displays data from the same field in a data source and/or user provided data and is represented by the Column class. 

Accessing columns

To access the grid's columns, the Columns property of the GridControl class can be used. For example, rather than using the Cells property of a CellRow class to alternate the column colors, the following code could be used once the grid is created to alternate the colors of the columns:

C# Copy Code
for( int i = 0; i < grid.Columns.Count; i = i + 2 )
{
   grid.Columns[ i ].BackColor = Color.LightBlue;
}

Manipulating columns

Columns can be manipulated using the ColumnManagerRow (if available). The ColumnManagerRow allows you to sort the contents of the columns as well as change their positions. When using the Grid Designer, the ColumnManagerRow also allows you to select columns to change their properties. 

To manipulate the columns programmatically, obtain a reference to the column to manipulate and modify its properties. For example, if you want to change the position of the last column to make it the first column, the following code can be used: 

C# Copy Code
// The last column will become the first column and all other
// columns will have their VisibleIndex incremented.
gridControl1.Columns[ gridControl1.Columns.Count - 1 ].VisibleIndex = 0;

Fixing columns

As of version 3.1, Xceed Grid for WinForms supports fixed columns. Programmatically, a column can be fixed by setting its Fixed property to true. At runtime, a column can be fixed by moving it to the left of the FixedColumnSplitter, or by moving the fixed column splitter (all columns to the left of the fixed column splitter will be fixed). 

Programmatically, when a column is fixed by setting its Fixed property to true, it will be appended to the right of the currently fixed columns. Its VisibleIndex property will not be modified allowing for the column to return to its previous visible index when its Fixed property is set to false

If a column is fixed through user interaction (dragging a column to the left of the fixed column splitter), its VisibleIndex will be modified to reflect its new position. If the column is then "un-fixed" programmatically by setting the Fixed property to false it may or may mot end up in its previous position (since the VisibleIndex property was modified). 

The fixed column splitter is accessible through the GridControl class as well as through the DetailGrid class; each having their own unique instances whose appearance and behavior can be modified. 

The fixed column splitters AllowRepositioning property indicates if it can be moved allowing for fixed columns to be added or removed. The Position property indicates the position of the fixed column splitter which will always be located to the immediate right of the fixed columns. The Position property also reflects the number of fixed columns in the grid. For example, if the grid contains 2 fixed columns, the position of the fixed column splitter will be 2 (zero-based). The Position property can be used to determine the number of fixed columns contained in the grid rather than consulting each Column's Fixed property. 

Each row in the grid that contains cells (CellRow) can chose to always show, or show only when there are fixed columns, its portion of the fixed column splitter by setting its ShowFixedColumnSplitter to Always or WhenFixedColumnsExist.   If set to Always the fixed column splitter will always be displayed. In the case where there are no fixed columns, the splitter will be located on the far left of the grid. If set to WhenFixedColumnsExist , the fixed column splitter will appear immediately after the fixed columns. 

The fixed column splitter's gripper will be painted in any and all ColumnManagerRows contained in the grid. To modify the appearance of the gripper or to prevent it from being painted, the PaintGripperBackground and PaintGripperForeground methods of the FixedColumnSplitter class can be overridden, or the Paint event handled. 

The following code demonstrates how to fix 2 columns programmatically (as demonstrated in the above image):

VB.NET Copy Code

GridControl1.Columns( "OrderID" ).Fixed = True
GridControl1.Columns( "EmployeeID" ).Fixed = True

C# Copy Code
gridControl1.Columns[ "OrderID" ].Fixed = true;
gridControl1.Columns[ "EmployeeID" ].Fixed = true;