DataGridViewRow.IsNewRow 属性

定义

获取一个值,指示行是否为用于新纪录的行。

public:
 property bool IsNewRow { bool get(); };
[System.ComponentModel.Browsable(false)]
public bool IsNewRow { get; }
[<System.ComponentModel.Browsable(false)>]
member this.IsNewRow : bool
Public ReadOnly Property IsNewRow As Boolean

属性值

Boolean

如果行是 DataGridView 中的最后一行(用于输入新数据行),则为 true;否则为 false

属性

示例

下面的代码示例使用该 IsNewRow 属性来防止尝试为新记录设置行的标签。

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

注解

由于新记录的行位于集合中 Rows ,因此使用 IsNewRow 属性来确定行是新记录的行还是填充的行。

当数据进入行开始时,行停止为新行。

适用于

另请参阅