DataGridView.CellEndEdit Evento

Definizione

Generato quando viene disattivata la modalità di modifica per la cella selezionata.Occurs when edit mode stops for the currently selected cell.

public:
 event System::Windows::Forms::DataGridViewCellEventHandler ^ CellEndEdit;
public event System.Windows.Forms.DataGridViewCellEventHandler CellEndEdit;
member this.CellEndEdit : System.Windows.Forms.DataGridViewCellEventHandler 
Public Custom Event CellEndEdit As DataGridViewCellEventHandler 

Tipo evento

DataGridViewCellEventHandler

Esempio

Nell'esempio di codice seguente viene illustrato come gestire questo evento per cancellare la DataGridViewRow.ErrorText proprietà Row nel caso in cui sia stata precedentemente impostata da un CellValidating gestore eventi.The following code example illustrates how to handle this event to clear the row DataGridViewRow.ErrorText property in case it was previously set by a CellValidating event handler. Il CellValidating gestore eventi può cancellare il testo dell'errore quando il nuovo valore di cella soddisfa i criteri di convalida, ma quando l'utente ripristina il valore della cella precedente premendo ESC, l' CellValidating evento non si verifica.The CellValidating event handler can clear the error text when the new cell value meets the validation criteria, but when the user reverts to the old cell value by pressing ESC, the CellValidating event does not occur. Questo esempio fa parte di un esempio più ampio disponibile in procedura dettagliata: convalida dei dati nel controllo DataGridView Windows Form.This example is part of a larger example available in Walkthrough: Validating Data in the Windows Forms DataGridView Control.

private void dataGridView1_CellValidating(object sender,
    DataGridViewCellValidatingEventArgs e)
{
    string headerText = 
        dataGridView1.Columns[e.ColumnIndex].HeaderText;

    // Abort validation if cell is not in the CompanyName column.
    if (!headerText.Equals("CompanyName")) return;

    // Confirm that the cell is not empty.
    if (string.IsNullOrEmpty(e.FormattedValue.ToString()))
    {
        dataGridView1.Rows[e.RowIndex].ErrorText =
            "Company Name must not be empty";
        e.Cancel = true;
    }
}

void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
    // Clear the row error in case the user presses ESC.   
    dataGridView1.Rows[e.RowIndex].ErrorText = String.Empty;
}
Private Sub dataGridView1_CellValidating(ByVal sender As Object, _
    ByVal e As DataGridViewCellValidatingEventArgs) _
    Handles dataGridView1.CellValidating

    Dim headerText As String = _
        dataGridView1.Columns(e.ColumnIndex).HeaderText

    ' Abort validation if cell is not in the CompanyName column.
    If Not headerText.Equals("CompanyName") Then Return

    ' Confirm that the cell is not empty.
    If (String.IsNullOrEmpty(e.FormattedValue.ToString())) Then
        dataGridView1.Rows(e.RowIndex).ErrorText = _
            "Company Name must not be empty"
        e.Cancel = True
    End If
End Sub

Private Sub dataGridView1_CellEndEdit(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
    Handles dataGridView1.CellEndEdit

    ' Clear the row error in case the user presses ESC.   
    dataGridView1.Rows(e.RowIndex).ErrorText = String.Empty

End Sub

Commenti

Per altre informazioni su come gestire gli eventi, vedere la gestione e generazione di eventi.For more information about how to handle events, see Handling and Raising Events.

Si applica a