BindingList(Of T).CancelNew Method (Int32)


Discards a pending new item.

Namespace:   System.ComponentModel
Assembly:  System (in System.dll)

Public Overridable Sub CancelNew (
	itemIndex As Integer


Type: System.Int32

The index of the of the new item to be added

The CancelNew method rolls back a pending new item that was added through the AddNew method, but has not yet been committed.

For more information about adding and committing new items, see the AddNew method

The following code example demonstrates how use the CancelNew method. For the complete example, see the BindingList(Of T) class overview topic.

' Add the new part unless the part number contains
' spaces. In that case cancel the add.
Private Sub button1_Click(ByVal sender As Object, _
    ByVal e As EventArgs) Handles button1.Click

    Dim newPart As Part = listOfParts.AddNew()

    If newPart.PartName.Contains(" ") Then
        MessageBox.Show("Part names cannot contain spaces.")
        textBox2.Text = randomNumber.Next(9999).ToString()
        textBox1.Text = "Enter part name"
    End If

End Sub

.NET Framework
Available since 2.0
Return to top