DataGrid.CurrentCell Property

Definition

Gets or sets which cell has the focus. Not available at design time.

C#
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.DataGridCell CurrentCell { get; set; }

Property Value

The DataGridCell with the focus.

Attributes

Examples

The following code example shows how to set and get the current cell.

C#
private void SetCellWithFocus(DataGrid myGrid)
 {
    // Set the current cell to cell1, row 1.
    myGrid.CurrentCell = new DataGridCell(1,1);
 }
 
 private void dataGrid1_GotFocus(object sender, EventArgs e)
 {
    Console.WriteLine(dataGrid1.CurrentCell.ColumnNumber + 
    " " + dataGrid1.CurrentCell.RowNumber);
 }

Remarks

Setting the CurrentCell property will cause the grid to scroll and show the cell if it is not already visible.

Applies to

Product Versions
.NET Framework 1.1, 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

See also