BindingList<T>.CancelNew(Int32) Método

Definição

Descarta um novo item pendente.Discards a pending new item.

public:
 virtual void CancelNew(int itemIndex);
public virtual void CancelNew (int itemIndex);
abstract member CancelNew : int -> unit
override this.CancelNew : int -> unit
Public Overridable Sub CancelNew (itemIndex As Integer)

Parâmetros

itemIndex
Int32

O índice do novo item a ser adicionadoThe index of the of the new item to be added

Implementações

Exemplos

O exemplo de código a seguir demonstra como usar o CancelNew método.The following code example demonstrates how use the CancelNew method. Para obter o exemplo completo, consulte o BindingList<T> tópico Visão geral da classe.For the complete example, see the BindingList<T> class overview topic.

// Add the new part unless the part number contains
// spaces. In that case cancel the add.
private void button1_Click(object sender, EventArgs e)
{
    Part newPart = listOfParts.AddNew();

    if (newPart.PartName.Contains(" "))
    {
        MessageBox.Show("Part names cannot contain spaces.");
        listOfParts.CancelNew(listOfParts.IndexOf(newPart));
    }
    else
    {
        textBox2.Text = randomNumber.Next(9999).ToString();
        textBox1.Text = "Enter part name";
    }
}
' 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.")
        listOfParts.CancelNew(listOfParts.IndexOf(newPart))
    Else
        textBox2.Text = randomNumber.Next(9999).ToString()
        textBox1.Text = "Enter part name"
    End If

End Sub

Comentários

O CancelNew método reverte um novo item pendente que foi adicionado por meio do AddNew método, mas ainda não foi confirmado.The CancelNew method rolls back a pending new item that was added through the AddNew method, but has not yet been committed.

Para obter mais informações sobre como adicionar e confirmar novos itens, consulte o AddNew métodoFor more information about adding and committing new items, see the AddNew method

Aplica-se a

Confira também