DataGridView.CurrentCellAddress 屬性

定義

取得目前的現用儲存格的資料列和資料行的索引。

public:
 property System::Drawing::Point CurrentCellAddress { System::Drawing::Point get(); };
[System.ComponentModel.Browsable(false)]
public System.Drawing.Point CurrentCellAddress { get; }
[<System.ComponentModel.Browsable(false)>]
member this.CurrentCellAddress : System.Drawing.Point
Public ReadOnly Property CurrentCellAddress As Point

屬性值

Point,表示目前作用中之儲存格的資料列和資料行索引。

屬性

範例

下列程式代碼範例說明如何在數據列繪製案例中使用 CurrentCellAddress 屬性。 在此範例中,這個屬性是用來儲存目前儲存格格的數據列索引。 當使用者將目前儲存格變更為不同的資料列時,數據列會強制重新繪製本身。

此程式代碼是如何:自定義 DataGridView 控件中 Windows Forms 數據列外觀中較大範例的一部分。

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

備註

使用這個屬性來判斷目前儲存格的數據列和數據行,而不需要直接存取儲存格。 這很適合避免共用共享的數據列。 如需數據列共用的詳細資訊,請參閱調整 Windows Forms DataGridView 控件的最佳做法

適用於

另請參閱