DataGridViewBand.Index Egenskap
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Hämtar bandets relativa position inom DataGridView kontrollen.
public:
property int Index { int get(); };
[System.ComponentModel.Browsable(false)]
public int Index { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Index : int
Public ReadOnly Property Index As Integer
Egenskapsvärde
Den nollbaserade positionen för bandet i DataGridViewRowCollection eller DataGridViewColumnCollection som det finns i. Standardvärdet är -1, vilket indikerar att det inte finns någon associerad DataGridView kontroll.
- Attribut
Exempel
I följande kodexempel används Index egenskapen för att ange kolumnetiketter. Bandets Index egenskap nås via en DataGridViewColumn.
Note
Om visuella format är aktiverade åsidosätter det aktuella temat visningsformatets egenskaper för rad- och kolumnrubriker.
// 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;
}
}
// Style and number columns.
private void Button8_Click(object sender,
EventArgs args)
{
DataGridViewCellStyle style = new DataGridViewCellStyle();
style.Alignment =
DataGridViewContentAlignment.MiddleCenter;
style.ForeColor = Color.IndianRed;
style.BackColor = Color.Ivory;
foreach (DataGridViewColumn column in dataGridView.Columns)
{
column.HeaderCell.Value = column.Index.ToString();
column.HeaderCell.Style = style;
}
}
' Style and number columns.
Private Sub Button8_Click(ByVal sender As Object, _
ByVal args As EventArgs) Handles Button8.Click
Dim style As DataGridViewCellStyle = _
New DataGridViewCellStyle()
style.Alignment = _
DataGridViewContentAlignment.MiddleCenter
style.ForeColor = Color.IndianRed
style.BackColor = Color.Ivory
For Each column As DataGridViewColumn _
In dataGridView.Columns
column.HeaderCell.Value = _
column.Index.ToString
column.HeaderCell.Style = style
Next
End Sub
Kommentarer
Värdet för den här egenskapen motsvarar inte nödvändigtvis den aktuella visuella positionen för bandet i samlingen. Om användaren till exempel ändrar ordning på kolumner i en DataGridView vid körning (förutsatt att AllowUserToOrderColumns egenskapen är inställd på true), ändras inte värdet för egenskapen för Index varje kolumn. Kolumnvärdena DisplayIndex ändras i stället. Sortering av rader ändrar dock deras Index värden.