ComponentOne True DBGrid for WinForms
Selecting Columns
Run-Time Interaction > Selection, Sorting, and Movement > Selecting Columns

If the AllowColSelect property is True, the user can select an individual column or a range of columns with the mouse. Nonadjacent column selections are not supported.

When the user points to the header of an unselected column, the mouse pointer changes to a down arrow to indicate that the column can be selected:


When the user clicks a column header, that column is selected and highlighted, and any columns or rows that were previously selected are deselected:


There are two ways for the user to select a range of columns:

In order to manipulate the columns that have been selected at run-time, query the SelectedColumnCollection. This is a collection of all the C1DataColumn objects for the selected columns. For instance, if columns 5 through 10 are selected, the SelectedColumnCollection will have six members, each a C1DataColumn object. This feature enables the display properties of the column to be altered directly. Using the Item property to access the C1DisplayColumn properties, the code to change the forecolor to red for the first column selected would be:

To write code in Visual Basic

Visual Basic
Copy Code
Dim dc as C1TrueDBGrid.C1DataColumn
 
dc = Me.C1TrueDBGrid1.SelectedCols(0)
Me.C1TrueDBGrid1.Splits(0).DisplayColumns(dc).Style.ForeColor = System.Drawing.Color.Red

To write code in C#

C#
Copy Code
dc as C1TrueDBGrid.C1DataColumn;
 
dc = this.c1TrueDBGrid1.SelectedCols[0];
this.c1TrueDBGrid1.Splits[0].DisplayColumns[dc].Style.ForeColor = System.Drawing.Color.Red;

Prevent a column selection from occurring at run time by setting the Cancelargument to True in the grid's SelChange event.

See Also