共用方式為


BindingList<T>.CancelNew(Int32) 方法

定義

捨棄暫止的新項目。

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)

參數

itemIndex
Int32

要加入之新專案的 索引。

實作

範例

下列程式代碼範例示範如何使用 CancelNew 方法。 如需完整的範例,請參閱 BindingList<T> 類別概觀主題。

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

備註

方法 CancelNew 會回復透過 AddNew 方法新增但尚未認可的暫止新專案。

如需新增和認可新專案的詳細資訊,請參閱 AddNew 方法

適用於

另請參閱