Xceed Grid for WinForms v4.3 Documentation
Handling Events

Welcome to Xceed Grid for WinForms v4.3 > Basic Concepts > Handling Events

An event is a message raised by an object to signal the occurrence of an action. In order to receive event notifications, a caller must subscribe to the desired events. 

The following events can be raised by Xceed Grid for WinForms:

Event Class Description
AddingDataRow event GridControl Raised when a new data row is about to be added to the grid.
DataRowsChanged and SiblingDataRowsChanged events GridControl, Group, and Row Raised when modifications are made to the content of a cell in a data row and when a data row (or sibling data row ) is added or removed from the grid.
EnteringEdit event Cell Raised before editing a cell.
GroupAdded event GridControl Raised when a group has been added to the grid.
InitializingDetailGrid event GridControl and DetailGrid Raised for each DataRow about to be added to the main grid or one of the detail grids to initialize its detail grid(s).
LeavingEdit event Cell Raised after a cell has been edited.
Mouse and keyboard events All classes Raised by various mouse and keyboard actions.
Paint event All classes Raised by each grid element after its has been painted in order to provide additional custom painting of the grid element's foreground.
PropertyChanged events All classes Raised when the value of a property changes.
QueryGroupKeys event GridControl Raised after a data row has been created in order to group it.
ValidationError events Cell, DataRow, and InsertionRow Raised by the AddNew or EndEdit methods when the value of a cell or one of the cells in a DataRow or InsertionRow does not pass the validation process.
ValueChanging event Cell Raised when a cell's value is being changed.
ExcelExporter events ExcelExporter Raised when the different parts of the spreadsheet being exported are being written.
Keep in mind that you should subscribe only to the necessary events to avoid needlessly decreasing performance.

Delegates

Each event has a corresponding delegate that is used to subscribe to the event. To subscribe, a new instance of the appropriate delegate class must be created and assigned to the corresponding event. In the constructor of the delegate class, we pass the name of the method that will handle the event(s) we are subscribing to. 

VB.NET Copy Code
Dim grid As New GridControl()
AddHandler grid.AddingDataRow, AddressOf Me.Grid_AddingDataRow
C# Copy Code
GridControl grid = new GridControl();
grid.AddingDataRow += new AddingDataRowEventHandler( this.grid_AddingDataRow );

The declaration of the event handler must have the same parameters as the EventHandler delegate declaration. The first parameter is the source of the event and the second is an argument class.

VB.NET Copy Code
Private Sub grid_AddingDataROw( ByVal sender As Object, ByVal e As AddingDataRowEventArgs )
End Sub
C# Copy Code
private void grid_AddingDataRow( object sender, AddingDataRowEventArgs e ){}