DataGridView.CurrentCellChanged 事件

定义

属性 CurrentCell 更改时发生。

public:
 event EventHandler ^ CurrentCellChanged;
public event EventHandler CurrentCellChanged;
public event EventHandler? CurrentCellChanged;
member this.CurrentCellChanged : EventHandler 
Public Custom Event CurrentCellChanged As EventHandler 

事件类型

示例

下面的代码示例演示了此事件的用法。 本示例是 “如何:自定义 Windows 窗体 DataGridView 控件中行的外观”的更大示例的一部分。

// Forces the row to repaint itself when the user changes the 
// current cell. This is necessary to refresh the focus rectangle.
void dataGridView1_CurrentCellChanged(object sender, EventArgs e)
{
    if (oldRowIndex != -1)
    {
        this.dataGridView1.InvalidateRow(oldRowIndex);
    }
    oldRowIndex = this.dataGridView1.CurrentCellAddress.Y;
}
' Forces the row to repaint itself when the user changes the 
' current cell. This is necessary to refresh the focus rectangle.
Sub dataGridView1_CurrentCellChanged(ByVal sender As Object, _
    ByVal e As EventArgs) Handles dataGridView1.CurrentCellChanged

    If oldRowIndex <> -1 Then
        Me.dataGridView1.InvalidateRow(oldRowIndex)
    End If
    oldRowIndex = Me.dataGridView1.CurrentCellAddress.Y

End Sub

注解

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

适用于

另请参阅