DataGridViewBand.Index 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得頻段在控制器中的 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
屬性值
包含於或DataGridViewColumnCollection中的帶DataGridViewRowCollection的零基位置。 預設值為 -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 (假設屬性 AllowUserToOrderColumns 設為 true),每個欄位屬性的 Index 值不會改變。 相反地,欄位 DisplayIndex 值會改變。 不過排序列會改變它們 Index 的值。