DataGridView.CancelEdit 方法

定义

取消当前选定单元格的编辑模式并丢弃所有更改。Cancels edit mode for the currently selected cell and discards any changes.

public:
 bool CancelEdit();
public bool CancelEdit ();
member this.CancelEdit : unit -> bool
Public Function CancelEdit () As Boolean

返回

如果取消操作成功,为 true;否则为 falsetrue if the cancel was successful; otherwise, false.

示例

下面的代码示例演示如何使用此方法。The following code example illustrates the use of this method. 此示例是Windows 窗体 DataGridView 控件中的列填充模式下提供的更大示例的一部分。This example is part of a larger example available in Column Fill Mode in the Windows Forms DataGridView Control.

private void ResetDataGridView()
{
    dataGridView1.CancelEdit();
    dataGridView1.Columns.Clear();
    dataGridView1.DataSource = null;
    InitializeDataGridView();
}
Private Sub ResetDataGridView()
    dataGridView1.CancelEdit()
    dataGridView1.Columns.Clear()
    dataGridView1.DataSource = Nothing
    InitializeDataGridView()
End Sub

适用于

另请参阅