DataGridViewRow.HeaderCell 屬性
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定資料列的行首儲存格。
public:
property System::Windows::Forms::DataGridViewRowHeaderCell ^ HeaderCell { System::Windows::Forms::DataGridViewRowHeaderCell ^ get(); void set(System::Windows::Forms::DataGridViewRowHeaderCell ^ value); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.DataGridViewRowHeaderCell HeaderCell { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.HeaderCell : System.Windows.Forms.DataGridViewRowHeaderCell with get, set
Public Property HeaderCell As DataGridViewRowHeaderCell
DataGridViewRowHeaderCell,表示資料列的行首儲存格。
- 屬性
下列程式碼範例會 HeaderCell 使用 屬性來標記資料列標頭。
// Set row labels.
void Button6_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
int rowNumber = 1;
System::Collections::IEnumerator^ myEnum = safe_cast<System::Collections::IEnumerable^>(dataGridView->Rows)->GetEnumerator();
while ( myEnum->MoveNext() )
{
DataGridViewRow^ row = safe_cast<DataGridViewRow^>(myEnum->Current);
if ( row->IsNewRow )
continue;
row->HeaderCell->Value = String::Format( L"Row {0}", rowNumber );
rowNumber = rowNumber + 1;
}
dataGridView->AutoResizeRowHeadersWidth( DataGridViewRowHeadersWidthSizeMode::AutoSizeToAllHeaders );
}
// Set row labels.
private void Button6_Click(object sender, System.EventArgs e)
{
int rowNumber = 1;
foreach (DataGridViewRow row in dataGridView.Rows)
{
if (row.IsNewRow) continue;
row.HeaderCell.Value = "Row " + rowNumber;
rowNumber = rowNumber + 1;
}
dataGridView.AutoResizeRowHeadersWidth(
DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);
}
' Set row labels.
Private Sub Button6_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Button6.Click
Dim rowNumber As Integer = 1
For Each row As DataGridViewRow In dataGridView.Rows
If row.IsNewRow Then Continue For
row.HeaderCell.Value = "Row " & rowNumber
rowNumber = rowNumber + 1
Next
dataGridView.AutoResizeRowHeadersWidth( _
DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders)
End Sub
資料列的標題儲存格通常用來顯示資料列標籤。 如果 屬性設定 DataGridViewSelectionMode.RowHeaderSelect 為 , DataGridView.SelectionMode 使用者也可以按一下資料列標頭來選取資料列。
產品 | 版本 |
---|---|
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |