DataGridView.RowLeave Evento

Definizione

Si verifica quando una riga perde lo stato attivo per l'input e non è più la riga corrente.Occurs when a row loses input focus and is no longer the current row.

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

Tipo evento

DataGridViewCellEventHandler

Esempio

Nell'esempio di codice seguente viene illustrato come gestire questo evento per modificare la BackColor proprietà delle celle nella riga corrente.The following code example illustrates how to handle this event to change the BackColor property of the cells in the current row. In questo esempio, il colore di sfondo viene impostato nell' RowEnter evento, quindi viene reimpostato Empty su sull' RowLeave evento.In this example, the background color is set in the RowEnter event, then reset to Empty on the RowLeave event. Per eseguire questo esempio, incollare il codice in un form che contiene un oggetto DataGridView denominato dataGridView1 e assicurarsi che tutti gli eventi siano associati ai relativi gestori eventi.To run this example, paste the code into a form that contains a DataGridView named dataGridView1 and ensure that all events are associated with their event handlers.

private void dataGridView1_RowEnter(object sender, 
    DataGridViewCellEventArgs e)
{
    for (int i = 0; i < dataGridView1.Rows[e.RowIndex].Cells.Count; i++)
    {
        dataGridView1[i, e.RowIndex].Style.BackColor = Color.Yellow;
    }
}

private void dataGridView1_RowLeave(object sender, 
    DataGridViewCellEventArgs e)
{
    for (int i = 0; i < dataGridView1.Rows[e.RowIndex].Cells.Count; i++)
    {
        dataGridView1[i, e.RowIndex].Style.BackColor = Color.Empty;
    }
}
Private Sub dataGridView1_RowEnter(ByVal sender As Object, _
    ByVal e As DataGridViewCellEventArgs) _
    Handles dataGridView1.RowEnter

    Dim i As Integer
    For i = 0 To dataGridView1.Rows(e.RowIndex).Cells.Count - 1
        dataGridView1(i, e.RowIndex).Style _
            .BackColor = Color.Yellow
    Next i

End Sub

Private Sub dataGridView1_RowLeave(ByVal sender As Object, _
    ByVal e As DataGridViewCellEventArgs) _
    Handles dataGridView1.RowLeave

    Dim i As Integer
    For i = 0 To dataGridView1.Rows(e.RowIndex).Cells.Count - 1
        dataGridView1(i, e.RowIndex).Style _
            .BackColor = Color.Empty
    Next i

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