DataGridView.CurrentCellAddress Właściwość

Definicja

Pobiera indeksy wierszy i kolumn aktualnie aktywnej komórki.

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

Wartość właściwości

Element Point reprezentujący indeksy wierszy i kolumn aktualnie aktywnej komórki.

Atrybuty

Przykłady

W poniższym przykładzie kodu pokazano, jak używać CurrentCellAddress właściwości w scenariuszu malowania wierszy. W tym przykładzie ta właściwość służy do przechowywania indeksu wierszy bieżącej komórki. Gdy użytkownik zmieni bieżącą komórkę na inny wiersz, wiersz zostanie zmuszony do ponownego zaintowania.

Ten kod jest częścią większego przykładu dostępnego w temacie How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control (Dostosowywanie wyglądu wierszy w kontrolce 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

Uwagi

Użyj tej właściwości, aby określić wiersz i kolumnę bieżącej komórki bez bezpośredniego dostępu do komórki. Jest to przydatne, aby uniknąć udostępniania udostępnionych wierszy. Aby uzyskać więcej informacji na temat udostępniania wierszy, zobacz Najlepsze rozwiązania dotyczące skalowania kontrolki Windows Forms DataGridView.

Dotyczy

Zobacz też