DataGridView.RowLeave 事件

定义

行失去输入焦点因而不再是当前行时发生。

public:
 event System::Windows::Forms::DataGridViewCellEventHandler ^ RowLeave;
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 

事件类型

示例

下面的代码示例演示如何处理此事件以更改 BackColor 当前行中单元格的属性。 在此示例中,背景色在 事件中RowEnter设置,然后在事件上RowLeave重置为 Empty 。 若要运行此示例,请将代码粘贴到包含 DataGridView 命名 dataGridView1 的窗体中,并确保所有事件都与其事件处理程序相关联。

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

注解

有关如何处理事件的详细信息,请参阅 处理和引发事件

适用于

另请参阅