Skip to main content

GridColumn.VisibleIndex Property

Gets or sets the column’s position within the View’s column header panel.

Namespace: DevExpress.XtraGrid.Columns

Assembly: DevExpress.XtraGrid.v22.2.dll

NuGet Package: DevExpress.Win.Grid


public virtual int VisibleIndex { get; set; }

Property Value

Type Default Description
Int32 -1

A column’s position within the View. -1 for hidden columns.


If you disable a column’s GridColumn.Visible setting, this hidden column will store its last known VisibleIndex internally. This allows the column to automatically restore its previous position when you set the Visible property back to true.

int A = columnPrice.VisibleIndex; // A returns "5"

//hide the "Price" column
columnPrice.Visible = false;
int B = columnPrice.VisibleIndex; // B returns "-1"

//show the "Price" column again
columnPrice.Visible = true;
int C = columnPrice.VisibleIndex; // C returns "5"

VisibleIndex for new columns

Columns added by the GridColumnCollection.Add method are initially hidden. To add a column and show it immediatelly, call the GridColumnCollection.AddVisible method instead.

GridColumn col1 = gridView1.Columns.Add();
//col1.Visible returns "false"
//col1.VisibleIndex returns "-1"

GridColumn col2 = gridView1.Columns.AddVisible(fieldName: "Category_Name", caption: "Category Name");
//the col2 column is instantly visible and placed last
//col2.Visible returns "true"
//col2.VisibleIndex returns "gridView1.VisibleColumns.Count - 1"

VisibleIndex for grouped columns

Grouped columns are considered as visible regardless of the GridOptionsView.ShowGroupedColumns setting.

gridView1.OptionsView.ShowGroupedColumns = false;

//colCategory.GroupIndex returns "-1"
//colCategory.Visible returns "true"
//colCategory.VisibleIndex returns "5"

colCategory.GroupIndex = 0;

//Grid data is now groupped by the "Category" column
//colCategory.Visible returns "true"
//colCategory.VisibleIndex returns "5"

For that reason, to iterate through all columns in the column header panel, use the VisibleColumns collection instead of the ColumnView.Columns collection.

Change VisibleIndex to move columns

If you decrease the VisibleIndex to move a column closer to the View’s left edge, the columns takes its new position as expected.

//the "Price" column is the 6th column in a View
//colPrice.VisibleIndex returns "5"

colPrice.VisibleIndex = 2;
//the "Price" column is now the 3rd column in a View
//colPrice.VisibleIndex = 2

If you increase the VisibleIndex to move a column to the View’s right edge, the column will be placed before the column that currently occupies the desired position.

//the "Model Name" column is the View's 1st column
//colModelName.VisibleIndex returns "0"

colModelName.VisibleIndex = 2;
//the "Model Name" column is now the 2nd column in a View
//colModelName.VisibleIndex returns "1"

The ColumnView.ColumnPositionChanged event fires whenever a column changes its position.

See Also