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 свойство в сценарии рисования строк. В примере это свойство используется для хранения индекса строки текущей ячейки. Когда пользователь изменяет текущую ячейку на другую строку, строка вынуждена перекрасить себя.

Этот код является частью более крупного примера, доступного в разделе 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

Комментарии

Это свойство используется для определения строки и столбца текущей ячейки без прямого доступа к ячейке. Это полезно, чтобы избежать отмены совместного использования общих строк. Дополнительные сведения о совместном использовании строк см. в статье Масштабирование элемента управления DataGridView в Windows Forms.

Применяется к

См. также раздел