DataGridView.CurrentCellChanged 事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
当 CurrentCell 属性更改时发生。
public:
event EventHandler ^ CurrentCellChanged;
public event EventHandler CurrentCellChanged;
member this.CurrentCellChanged : EventHandler
Public Custom Event CurrentCellChanged As 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
注解
有关如何处理事件的详细信息,请参阅 处理和引发事件。