DataGridViewBand::Index Property
Gets the relative position of the band within the DataGridView control.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Property Value
Type: System::Int32The zero-based position of the band in the DataGridViewRowCollection or DataGridViewColumnCollection that it is contained within. The default is -1, indicating that there is no associated DataGridView control.
The value of this property does not necessarily correspond to the current visual position of the band within the collection. For example, if the user reorders columns in a DataGridView at run time (assuming the AllowUserToOrderColumns property is set to true), the value of the Index property of each column will not change. Instead, the column DisplayIndex values change. Sorting rows, however, does change their Index values.
The following code example uses the Index property to set column labels. The band's Index property is accessed through a DataGridViewColumn.
Note |
|---|
If visual styles are enabled, the current theme overrides the display style properties for row and column headers. |
// Style and number columns. void Button8_Click( Object^ /*sender*/, EventArgs^ /*args*/ ) { DataGridViewCellStyle^ style = gcnew DataGridViewCellStyle; style->Alignment = DataGridViewContentAlignment::MiddleCenter; style->ForeColor = Color::IndianRed; style->BackColor = Color::Ivory; IEnumerator^ myEnum1 = dataGridView->Columns->GetEnumerator(); while ( myEnum1->MoveNext() ) { DataGridViewColumn^ column = safe_cast<DataGridViewColumn^>(myEnum1->Current); column->HeaderCell->Value = column->Index.ToString(); column->HeaderCell->Style = style; } }
Available since 2.0
