This documentation is archived and is not being maintained.

DataGrid.CurrentCellChanged Event

Occurs when the CurrentCell property has changed.

[Visual Basic]
Public Event CurrentCellChanged As EventHandler
[C#]
public event EventHandler CurrentCellChanged;
[C++]
public: __event EventHandler* CurrentCellChanged;

[JScript] In JScript, you can handle the events defined by a class, but you cannot define your own.

Event Data

The event handler receives an argument of type EventArgs.

Remarks

To determine the current cell, use the CurrentCell property.

For more information about handling events, see Consuming Events.

Example

[Visual Basic] 
' Create an instance of the 'CurrentCellChanged' EventHandler.
Private Sub CallCurrentCellChanged()
   AddHandler myDataGrid.CurrentCellChanged, AddressOf Grid_CurCellChange
End Sub 'CallCurrentCellChanged


' Raise the event when focus on DataGrid cell changes.
Protected Sub Grid_CurCellChange(sender As Object, e As EventArgs)
   ' String variable used to show message.
   Dim myString As String = "CurrentCellChanged event raised, cell focus is at "
   ' Get the co-ordinates of the focussed cell.
   Dim myPoint As String = myDataGrid.CurrentCell.ColumnNumber + "," + myDataGrid.CurrentCell.RowNumber
   ' Create the alert message.
   myString = myString + "(" + myPoint + ")"
   ' Show Co-ordinates when CurrentCellChanged event is raised.
   MessageBox.Show(myString, "Current cell co-ordinates")
End Sub 'Grid_CurCellChange


[C#] 
// Create an instance of the 'CurrentCellChanged' EventHandler.
private void CallCurrentCellChanged()
{
   myDataGrid.CurrentCellChanged += new EventHandler(Grid_CurCellChange);
}

// Raise the event when focus on DataGrid cell changes.
protected void Grid_CurCellChange(object sender, EventArgs e)
{
   // String variable used to show message.
   string myString = "CurrentCellChanged event raised, cell focus is at ";
   // Get the co-ordinates of the focussed cell.
   string myPoint  = myDataGrid.CurrentCell.ColumnNumber + "," +
                  myDataGrid.CurrentCell.RowNumber;
   // Create the alert message.
   myString = myString + "(" + myPoint + ")";
   // Show Co-ordinates when CurrentCellChanged event is raised.
   MessageBox.Show(myString, "Current cell co-ordinates");
}

[C++] 
// Create an instance of the 'CurrentCellChanged' EventHandler.
private:
void CallCurrentCellChanged() {
    myDataGrid->CurrentCellChanged += new EventHandler(this, &MyDataGrid::Grid_CurCellChange);
}

// Raise the event when focus on DataGrid cell changes.
protected:
void Grid_CurCellChange(Object* /*sender*/, EventArgs* /*e*/) {
    // String variable used to show message.
    String* myString = S"CurrentCellChanged event raised, cell focus is at ";
    // Get the co-ordinates of the focussed cell.
    String* myPoint  = String::Concat(__box(myDataGrid->CurrentCell.ColumnNumber), 
        S", ", __box(myDataGrid->CurrentCell.RowNumber));
    // Create the alert message.
    myString = String::Concat(myString, S"(", myPoint, S")");
    // Show Co-ordinates when CurrentCellChanged event is raised.
    MessageBox::Show(myString, S"Current cell co-ordinates");
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

DataGrid Class | DataGrid Members | System.Windows.Forms Namespace

Show: