DataGridViewRow.IsNewRow Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets a value indicating whether the row is the row for new records.
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
true
if the row is the last row in the DataGridView, which is used for the entry of a new row of data; otherwise, false
.
- Attributes
The following code example uses the IsNewRow property to prevent attempts to set the label of the row for new records.
// 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
Because the row for new records is in the Rows collection, use the IsNewRow property to determine whether a row is the row for new records or is a populated row.
A row stops being the new row when data entry into the row begins.
Product | Versions |
---|---|
.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 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: