DataGridView::SelectionChanged Event

 

Occurs when the current selection changes.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public:
event EventHandler^ SelectionChanged {
	void add(EventHandler^ value);
	void remove(EventHandler^ value);
}

This event occurs whenever cells are selected or the selection is canceled, whether programmatically or by user action. For example, this event is useful when you want display the sum of the currently selected cells.

When you change the value of the CurrentCell property, the SelectionChanged event occurs before the CurrentCellChanged event. Any SelectionChanged event handler accessing the CurrentCell property at this time will get its previous value.

For more information about handling events, see NIB: Consuming Events.

The following code example demonstrates the use of this event. In the example, the form displays the sum of values in the selected cells, and updates the sum when the selection changes.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Return to top
Show: