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

備註

如需如何處理事件的詳細資訊,請參閱 處理和引發事件

適用於

另請參閱