다음을 통해 공유


DataGridViewBand.Index 속성

정의

컨트롤 내에서 대역의 상대 위치를 가져옵니다 DataGridView .

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

속성 값

0부터 시작하는 대역 DataGridViewRowCollection 내의 위치이거나 DataGridViewColumnCollection 그 안에 들어 있는 위치입니다. 기본값은 -1로, 연결된 컨트롤이 없음을 DataGridView 나타냅니다.

특성

예제

다음 코드 예제에서는 열 레이블을 Index 설정 하는 속성을 사용 합니다. 밴드의 Index 속성은 .를 DataGridViewColumn통해 액세스됩니다.

메모

비주얼 스타일을 사용 하는 경우 현재 테마 행 및 열 머리글에 대 한 표시 스타일 속성을 재정의 합니다.

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

설명

이 속성의 값이 반드시 컬렉션 내에서 대역의 현재 시각적 위치에 해당 하지는 않습니다. 예를 들어 사용자가 런타임에 DataGridView 열을 다시 정렬하는 경우(속성이 설정된 true것으로 가정AllowUserToOrderColumns) 각 열의 Index 속성 값이 변경되지 않습니다. 대신 열 DisplayIndex 값이 변경됩니다. 그러나 행을 정렬하면 해당 값이 변경 Index 됩니다.

적용 대상

추가 정보