Xceed Grid for WinForms v4.3 Documentation
How to subscribe to the events of each cell

Welcome to Xceed Grid for WinForms v4.3 > Task-Based Help > Events > How to subscribe to the events of each cell

The best way to subscribe to the events of each cell in the grid is to subscribe to the events of each cell in the DataRowTemplate

If your grid is data bound, in order to subscribe to the events of each cell in the DataRowTemplate, you will need to bind the grid between calls to the grid's BeginInit and EndInit methods. 

If you are providing data manually (unbound mode), then the columns need to be added to the grid before subscribing to the events of each cell in the DataRowTemplate. Once you have subscribed to the events, you can then add your data.

Demonstration

The following example demonstrates how to subscribe to the events of each cell in a data bound grid.

VB.NET Copy Code

GridControl1.BeginInit() 

GridControl1.DataSource = DataSet11
GridControl1.DataMember = "Orders" 

Dim cell As DataCell
For Each cell In GridControl1.DataRowTemplate.Cells
  AddHandler cell.Click, AddressOf Me.cell_Click
Next cell 

GridControl1.EndInit()

C# Copy Code

gridControl1.BeginInit(); 

gridControl1.DataSource = dataSet11;
gridControl1.DataMember = "Orders"; 

foreach( DataCell cell in gridControl1.DataRowTemplate.Cells )
{
  cell.Click += new EventHandler( this.cell_Click );

gridControl1.EndInit();

For more information on how to use the BeginInit and EndInit methods, jump to the Batch Modifications topic.

The next example demonstrates how to subscribe to the events of each cell in an unbound grid.

VB.NET Copy Code

GridControl1.Columns.Add( New Column( "first" ) )
GridControl1.Columns.Add( New Column( "second" ) )
GridControl1.Columns.Add( New Column( "third" ) )
GridControl1.Columns.Add( New Column( "fourth" ) ) 

Dim cell As DataCell
For Each cell In GridControl1.DataRowTemplate.Cells
  AddHandler cell.Click, AddressOf Me.cell_Click
Next cell 

AddHandler GridControl1.AddingDataRow, AddressOf Me.AddingRows 

Dim i As Integer 

For i = 0 To 20
  GridControl1.DataRows.AddNew().EndEdit()
Next i

C# Copy Code

gridControl1.Columns.Add( new Column( "first" ) );
gridControl1.Columns.Add( new Column( "second" ) );
gridControl1.Columns.Add( new Column( "third" ) );
gridControl1.Columns.Add( new Column( "fourth" ) ); 

foreach( DataCell cell in gridControl1.DataRowTemplate.Cells )
{
  cell.Click += new EventHandler( this.cell_Click );

gridControl1.AddingDataRow += new AddingDataRowEventHandler( this.AddingRows ); 

for( int i = 0; i < 20; i++ )
{
  gridControl1.DataRows.AddNew().EndEdit();
}