Xceed Grid for WinForms v4.3 Documentation
Welcome to Xceed Grid for WinForms v4.3 / Basic Concepts / Events / Using the AddingDataRow event

In This Topic
    Using the AddingDataRow event
    In This Topic

    The AddingDataRow event is raised when a new data row is about to be added to the grid. It allows you to provide data manually to the row's cells or to modify the data being read from the data source.

    Basic steps - C#

    To subscribe to the AddingDataRow event, the following steps must be performed:

    • Obtain a reference to a GridControl object. 

    • Subscribe to the AddingDataRow event of the GridControl object using the AddingDataRowEventHandler delegate class 

    • Create a new method that will handle the events that are raised. 

    • Place the desired code in the newly created event handler.

    Basic steps - VB.NET

    To subscribe to the AddingDataRow event, the following steps must be performed:

    • Obtain a reference to a GridControl object. 

    • Subscribe to the AddingDataRow event of the GridControl object using the AddHandler/AddressOf keywords. 

    • Create a new method that will handle the events that are raised. 

    • Place the desired code in the newly created event handler.

    Demonstration

    This example assumes that you are in a Windows application.

    VB.NET Copy Code
    Imports Xceed.Grid

    AddHandler gridControl1.AddingDataRow, AddressOf Me.grid_AddingDataRow
     
    Dim random As New Random()
    ' This method will handle the AddingDataRow events that are raised.
    Private Sub grid_AddingDataRow( ByVal sender As Object, ByVal e As AddingDataRowEventArgs )
       Try
          Dim cell As DataCell
          For Each cell in e.DataRow.Cells
             cell.Value = random.Next().ToString()
          Next cell
       Catch exception As Exception
           MessageBox.Show( exception.ToString() )
       End Try
    End Sub

    ' If you no longer wish to handle the AddingDataRow events that are raised,
    ' you can unsubscribe from the event notification by doing the following:

    RemoveHandler gridControl1.AddingDataRow, AddressOf Me.grid_AddingDataRow
    C# Copy Code
    using Xceed.Grid;

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

    Random random = new Random();
    // This method will handle the AddingDataRow events that are raised.
    private void grid_AddingDataRow( object sender, AddingDataRowEventArgs e )
    {
       try
       {
          foreach( DataCell cell in e.DataRow.Cells )
          {
              cell.Value = random.Next().ToString();
          }
       }
       catch( Exception exception )
       {
          MessageBox.Show( exception.ToString );
       }
    }