DataGridViewRow.IsNewRow Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets a value indicating whether the row is the row for new records.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

<BrowsableAttribute(False)>
Public ReadOnly Property IsNewRow As Boolean

Property Value

Type: System.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.

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.

The following code example uses the IsNewRow property to prevent attempts to set the label of the row for new records.

' 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

.NET Framework
Available since 2.0
Return to top
Show: