DataGridViewRow.HeaderCell DataGridViewRow.HeaderCell DataGridViewRow.HeaderCell DataGridViewRow.HeaderCell Property

定義

行のヘッダー セルを取得または設定します。Gets or sets the row's header cell.

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; }
member this.HeaderCell : System.Windows.Forms.DataGridViewRowHeaderCell with get, set
Public Property HeaderCell As DataGridViewRowHeaderCell

プロパティ値

次のコード例ではHeaderCell 、プロパティを使用して行ヘッダーにラベルを付けています。The following code example uses the HeaderCell property to label row headers.

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

注釈

行のヘッダーセルは、通常、行ラベルを表示するために使用されます。The header cell of a row is typically used to display a row label. また、 DataGridView.SelectionModeプロパティがにDataGridViewSelectionMode.RowHeaderSelect設定されている場合は、行ヘッダーをクリックして行を選択することもできます。Users can also click the row header to select the row if the DataGridView.SelectionMode property is set to DataGridViewSelectionMode.RowHeaderSelect.

適用対象

こちらもご覧ください