DataGridView.CurrentCellAddress Property

Definition

Gets the row and column indexes of the currently active cell.

C#
[System.ComponentModel.Browsable(false)]
public System.Drawing.Point CurrentCellAddress { get; }

Property Value

A Point that represents the row and column indexes of the currently active cell.

Attributes

Examples

The following code example illustrates how to use the CurrentCellAddress property in a row-painting scenario. In the example, this property is used to store the row index of the current cell. When the user changes the current cell to a different row, the row is forced to repaint itself.

This code is part of a larger example available in How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control.

C#
// 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;
}

Remarks

Use this property to determine the row and column of the current cell without accessing the cell directly. This is useful to avoid unsharing shared rows. For more information about row sharing, see Best Practices for Scaling the Windows Forms DataGridView Control.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also