DataGridView.CancelRowEdit Evento

Definição

Ocorre quando a propriedade VirtualMode de um controle DataGridView é true e cancela as edições em uma linha.

public:
 event System::Windows::Forms::QuestionEventHandler ^ CancelRowEdit;
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 a seguir ilustra como manipular esse evento para um DataGridView controle no modo virtual. Quando o controle está no modo de edição, a rowInEdit variável mantém o índice da linha que está sendo editada e a customerInEdit variável mantém uma referência a um objeto Customer correspondente a essa linha. Quando o usuário cancela o modo de edição, esse objeto pode ser descartado. Se a linha que o usuário estava editando for a linha para novos registros, no entanto, o objeto Customer antigo será descartado e substituído por um novo para que o usuário possa começar a fazer edições novamente. Este exemplo faz parte de um exemplo maior disponível em Passo a passo: implementando o modo virtual no Windows Forms controle DataGridView.

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

Comentários

Quando o DataGridView está no modo virtual, as alterações são confirmadas no cache de dados no nível da célula por padrão. O CancelRowEdit evento pode ser usado ao implementar transações em nível de linha.

Para obter mais informações sobre como lidar com eventos, consulte Manipulando e levantando eventos.

Aplica-se a

Confira também