Windows Dev Center

Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DataGrid.CurrentCell Property

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

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public DataGridCell CurrentCell { get; set; }
/** @property */
public DataGridCell get_CurrentCell ()

/** @property */
public void set_CurrentCell (DataGridCell value)

public function get CurrentCell () : DataGridCell

public function set CurrentCell (value : DataGridCell)

Not applicable.

Property Value

The DataGridCell with the focus.

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

Windows Mobile 2003 for Pocket PC, Windows Mobile 2003 for Smartphone, Windows CE Platform Note: On the .NET Compact Framework, this member throws a Exception if you try to set the current cell when the grid has no active table style.

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

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);
 }
    

private void SetCellWithFocus(DataGrid myGrid)
{
    // Set the current cell to cell1, row 1.
    myGrid.set_CurrentCell(new DataGridCell(1, 1));
} //SetCellWithFocus

private void dataGrid1_GotFocus(Object sender, EventArgs e)
{
    Console.WriteLine(dataGrid1.get_CurrentCell().get_ColumnNumber()
        + " " + dataGrid1.get_CurrentCell().get_RowNumber());
} //dataGrid1_GotFocus

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

Show:
© 2015 Microsoft