BindingList<T>.CancelNew(Int32) Metodo

Definizione

Elimina un nuovo elemento in attesa.

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)

Parametri

itemIndex
Int32

Indice dell'oggetto del nuovo elemento da aggiungere.

Implementazioni

Esempio

Nell'esempio di codice seguente viene illustrato come usare il CancelNew metodo . Per l'esempio completo, vedere l'argomento panoramica della BindingList<T> classe.

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

Commenti

Il CancelNew metodo esegue il rollback di un nuovo elemento in sospeso aggiunto tramite il metodo , ma non è stato ancora eseguito il AddNew commit.

Per altre informazioni sull'aggiunta e il commit di nuovi elementi, vedere il AddNew metodo

Si applica a

Vedi anche