DataGridView.CurrentCellChanged 事件

定义

CurrentCell 属性更改时发生。

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

事件类型

EventHandler

示例

下面的代码示例演示了此事件的用法。 此示例是 How to: Customize the Appearance of Rows in the Windows 窗体 DataGridView Control 中提供的大型示例的一部分。

// 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

注解

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

适用于

另请参阅