DataGridView.CancelRowEdit Evento
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Ocorre quando a VirtualMode propriedade de um DataGridView controlo é true e o utilizador cancela edições seguidas.
public:
event System::Windows::Forms::QuestionEventHandler ^ CancelRowEdit;
public event System.Windows.Forms.QuestionEventHandler CancelRowEdit;
member this.CancelRowEdit : System.Windows.Forms.QuestionEventHandler
Public Custom Event CancelRowEdit As QuestionEventHandler
Tipo de Evento
Exemplos
O exemplo de código seguinte ilustra como lidar com este evento para um DataGridView controlo em modo virtual. Quando o controlo está em modo de edição, a rowInEdit variável contém o índice da linha a editar, e a customerInEdit variável mantém uma referência a um objeto Customer correspondente a essa linha. Quando o utilizador cancela o modo de edição, este objeto pode ser descartado. Se a linha que o utilizador estava a editar for a linha para novos registos, no entanto, o antigo objeto Customer é descartado e substituído por um novo para que o utilizador possa voltar a fazer edições. Este exemplo faz parte de um exemplo mais amplo disponível em Walkthrough: Implementing Virtual Mode in the Windows Forms DataGridView Control.
void dataGridView1_CancelRowEdit( Object^ /*sender*/,
System::Windows::Forms::QuestionEventArgs^ /*e*/ )
{
if ( this->rowInEdit == this->dataGridView1->Rows->Count - 2 &&
this->rowInEdit == this->customers->Count )
{
// If the user has canceled the edit of a newly created row,
// replace the corresponding Customer object with a new, empty one.
this->customerInEdit = gcnew Customer;
}
else
{
// If the user has canceled the edit of an existing row,
// release the corresponding Customer object.
this->customerInEdit = nullptr;
this->rowInEdit = -1;
}
}
private void dataGridView1_CancelRowEdit(object sender,
System.Windows.Forms.QuestionEventArgs e)
{
if (this.rowInEdit == this.dataGridView1.Rows.Count - 2 &&
this.rowInEdit == this.customers.Count)
{
// If the user has canceled the edit of a newly created row,
// replace the corresponding Customer object with a new, empty one.
this.customerInEdit = new Customer();
}
else
{
// If the user has canceled the edit of an existing row,
// release the corresponding Customer object.
this.customerInEdit = null;
this.rowInEdit = -1;
}
}
Private Sub dataGridView1_CancelRowEdit(ByVal sender As Object, _
ByVal e As System.Windows.Forms.QuestionEventArgs) _
Handles dataGridView1.CancelRowEdit
If Me.rowInEdit = Me.dataGridView1.Rows.Count - 2 AndAlso _
Me.rowInEdit = Me.customers.Count Then
' If the user has canceled the edit of a newly created row,
' replace the corresponding Customer object with a new, empty one.
Me.customerInEdit = New Customer()
Else
' If the user has canceled the edit of an existing row,
' release the corresponding Customer object.
Me.customerInEdit = Nothing
Me.rowInEdit = -1
End If
End Sub
Observações
Quando está DataGridView em modo virtual, as alterações são comprometidas por defeito para a cache de dados ao nível da célula. O CancelRowEdit evento pode ser usado ao implementar transações ao nível da linha.
Para mais informações sobre como gerir eventos, consulte Gestão e Levantamento de Eventos.