Sdílet prostřednictvím


DataGridViewBand.Index Vlastnost

Definice

Získá relativní pozici pásma uvnitř DataGridView ovládacího prvku.

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

Hodnota vlastnosti

Nulová pozice pásma v pásmu DataGridViewRowCollection nebo DataGridViewColumnCollection v tom, že je obsažena uvnitř. Výchozí hodnota je -1, což znamená, že neexistuje žádný přidružený DataGridView ovládací prvek.

Atributy

Příklady

Následující příklad kódu používá Index vlastnost k nastavení popisků sloupců. Vlastnost kapely Index je přístupná prostřednictvím objektu DataGridViewColumn.

Poznámka:

Pokud jsou styly vizuálů povolené, aktuální motiv přepíše vlastnosti stylu zobrazení pro záhlaví řádků a sloupců.

// 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

Poznámky

Hodnota této vlastnosti nemusí nutně odpovídat aktuální vizuální pozici pásma v kolekci. Pokud například uživatel změní pořadí sloupců v DataGridView době běhu (za předpokladu, že AllowUserToOrderColumns je vlastnost nastavena na true), hodnota Index vlastnosti každého sloupce se nezmění. Místo toho se hodnoty sloupců DisplayIndex mění. Řazení řádků ale změní jejich Index hodnoty.

Platí pro

Viz také