Xceed Grid for WinForms v4.3 Documentation
AddingDataRow Event (DetailGrid)
Example 


Xceed.Grid.v4.3 Assembly > Xceed.Grid Namespace > DetailGrid Class : AddingDataRow Event
Raised when a new data row is being added to the grid.
Syntax
'Declaration
 
<DescriptionAttribute("Raised when a new data row is about to be added to the grid.")>

<CategoryAttribute("Data")>

Public Event AddingDataRow As AddingDataRowEventHandler
'Usage
 
Dim instance As DetailGrid

Dim handler As AddingDataRowEventHandler

 

AddHandler instance.AddingDataRow, handler
[Description("Raised when a new data row is about to be added to the grid.")]

[Category("Data")]

public event AddingDataRowEventHandler AddingDataRow
Event Data

The event handler receives an argument of type AddingDataRowEventArgs containing data related to this event. The following AddingDataRowEventArgs properties provide information specific to this event.

PropertyDescription
Gets a reference to the DataRow object being built.  
Remarks

When bound to a data source, the AddingDataRow event is raised for each row found in the data source. When in unbound mode (providing data manually), it is raised once for each DataRow added using the Xceed.Grid.Collections.DataRowList.AddNew method afterEndEdit is called in order to provide data to each cell in the row.

Example
The following example demonstrates how to create a grid whose data is provided manually using the AddingDataRow event.
' Add the desired number of columns to the grid. 

' In the case, we will only add 4

gridControl1.Columns.Add( New Column( "column1", GetType( Integer ) ) )

gridControl1.Columns.Add( New Column( "column2", GetType( Integer ) ) )

gridControl1.Columns.Add( New Column( "column3", GetType( Integer ) ) )

gridControl1.Columns.Add( New Column( "column4", GetType( Integer ) ) )



 ' Subscribe to the AddingDataRow event

 AddHandler gridControl1.AddingDataRow, AddressOf Me.grid_AddingDataRow



' Add the desired number of DataRow objects to the grid's collection of datarows

Dim i As Integer

For i = 0 To 50

   gridControl1.DataRows.AddNew().EndEdit();

   

   ' AddNew will return a reference to a new DataRow object whose 

   ' cell values we can fill immediately, for the purposes of this

   ' example we will use the AddingDataRow event instead.

   '

   ' Xceed.Grid.DataRow row = gridControl1.DataRows.AddNew()

   ' row.Cells( 0 ).Value = 26

   ' row.Cells( 0 ).Value = 27

   ' row.Cells( 0 ).Value = 28

   ' row.Cells( 0 ).Value = 29

   ' row.EndEdit();

   ' etc...

 Next

     

 ' Private member variables that will be used to provide data to the grid.

 private m_random As new Random()

 

 ' This is the procedure that will handle the AddingDataRow event.

 Private Sub grid_AddingDataRow( ByVal sender As Object, ByVal e As AddingDataRowEventArgs )

    Dim cell As Cell

    

    Try

       For Each( cell in e.DataRow.Cells ) 

          cell.Value = m_random.Next( 0, 5000 )

       Next cell

    Catch exception As Exception

       MessageBox.Show( exception.ToString() )

    End Try   

End Sub
// Add the desired number of columns to the grid. 

// In the case, we will only add 4

gridControl1.Columns.Add( new Column( "column1", typeof( int ) ) );

gridControl1.Columns.Add( new Column( "column2", typeof( int ) ) );

gridControl1.Columns.Add( new Column( "column3", typeof( int ) ) );

gridControl1.Columns.Add( new Column( "column4", typeof( int ) ) );



// Subscribe to the AddingDataRow event

gridControl1.AddingDataRow += new AddingDataRowEventHandler( grid_AddingDataRow );



// Add the desired number of DataRow objects to the grid's collection of datarows

for( int i = 0; i != 50; i++ )

{

   gridControl1.DataRows.AddNew().EndEdit();

   

   // AddNew will return a reference to a new DataRow object whose 

   // cell values we can fill immediately, for the purposes of this

   // example we will use the AddingDataRow event instead.

   //

   // Xceed.Grid.DataRow row = gridControl1.DataRows.AddNew();

   // row.Cells[ 0 ].Value = 25;

   // row.Cells[ 1 ].Value = 26;

   // row.Cells[ 2 ].Value = 27;

   // row.Cells[ 3 ].Value = 28;

   // row.EndEdit();

   // etc...

}



// Private member variables that will be used to provide data to the grid.

private Random m_random = new Random(); 



// This is the procedure that will handle the AddingDataRow event.

private void grid_AddingDataRow( object sender, AddingDataRowEventArgs e )

{

   try

   {

      foreach( Cell cell in e.DataRow.Cells ) 

      {

         cell.Value = m_random.Next( 0, 5000 ); 

      }   

   }

   catch( Exception exception )

   {

      MessageBox.Show( exception.ToString() );

   }   

}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also