Version

BeforeRowInsert Event

Occurs before a new row is inserted.
Syntax
'Declaration
 
Public Event BeforeRowInsert As BeforeRowInsertEventHandler
public event BeforeRowInsertEventHandler BeforeRowInsert
Event Data

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

PropertyDescription
Band The band (read-only)
Cancel (Inherited from System.ComponentModel.CancelEventArgs) 
ParentRow The parent row (read-only)
Remarks

The band argument returns a reference to an UltraGridBand object that can be used to set properties of, and invoke methods on, the band into which the new row will be inserted. You can use this reference to access any of the returned band's properties or methods.

The parentrow argument returns a reference to an UltraGridRow object that can be used to set properties of, and invoke methods on, the row that will be the parent of the row to be inserted. You can use this reference to access any of the returned row's properties or methods. If the row being inserted is not a child, parentrow will be set to Nothing.

The cancel argument enables you to programmatically prevent the row from being inserted. This argument can be used to prevent the user from inserting a new row unless a certain condition is met.

This event is generated after a new row has been inserted, either programmatically, or by user interaction. A new row can be inserted programmatically by invoking the AddNew method.

The AfterRowInsert event, which occurs after a row is inserted, is generated after this event, provided cancel is not set to True.

Example
Following code illustrates some of the information available in BeforeRowInsert event and its potential uses.

For an overview of how to handle events in Visual Basic or Visual C#, see Event Handlers in Visual Basic and Visual C#. For specific information and code examples illustrating how to consume events in your application, see Consuming Events in the .NET Framework Developer's Guide.

Imports Infragistics.Shared
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinGrid
Imports System.Diagnostics

   Private Sub UltraGrid1_BeforeRowInsert(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.BeforeRowInsertEventArgs) Handles ultraGrid1.BeforeRowInsert

       ' BeforeRowInsert gets fired when the user clicks on an add-new button in
       ' the add-new-box to add a row. This event gives you a chance to prevent
       ' the user from doing so conditionally by setting Cancel to true.

       ' You can also access the rows collection the row would be added to.
       Dim rowsColl As RowsCollection = Nothing
       If Nothing Is e.ParentRow Then
           ' If ParentRow is null, then the row is being added to the topmost rows collection
           ' which can be accessed by using the Rows property off the UltraGrid.
           rowsColl = Me.ultraGrid1.Rows
       Else
           ' If ParentRow is non-null, then the row is being added to a descendant band. Here
           ' is how you can get the rows collection.
           rowsColl = e.ParentRow.ChildBands(e.Band).Rows
       End If

       Debug.WriteLine("Row is being added to rows collection with " & rowsColl.Count.ToString() & " number of rows.")

       Dim result As DialogResult = MessageBox.Show("You are about to add a row to " & e.Band.Key & ". Continue ?", _
                                                       "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

       ' Set cancel to stop the UltraGrid from proceeding with adding of a new row.
       If DialogResult.No = result Then
           e.Cancel = True
       End If

   End Sub
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using System.Diagnostics;

private void ultraGrid1_BeforeRowInsert(object sender, Infragistics.Win.UltraWinGrid.BeforeRowInsertEventArgs e)
{

	// BeforeRowInsert gets fired when the user clicks on an add-new button in
	// the add-new-box to add a row. This event gives you a chance to prevent
	// the user from doing so conditionally by setting Cancel to true.

	// You can also access the rows collection the row would be added to.
	RowsCollection rowsColl = null;
	if ( null == e.ParentRow )
	{
		// If ParentRow is null, then the row is being added to the topmost rows collection
		// which can be accessed by using the Rows property off the UltraGrid.
		rowsColl = this.ultraGrid1.Rows;
	}
	else
	{
		// If ParentRow is non-null, then the row is being added to a descendant band. Here
		// is how you can get the rows collection.
		rowsColl = e.ParentRow.ChildBands[ e.Band ].Rows;
	}

	Debug.WriteLine( "Row is being added to rows collection with " + rowsColl.Count.ToString( ) + " number of rows." );

	DialogResult result = MessageBox.Show( 
		"You are about to add a row to " + e.Band.Key + ". Continue ?", "Confirm",
		MessageBoxButtons.YesNo, MessageBoxIcon.Question );

	// Set cancel to stop the UltraGrid from proceeding with adding of a new row.
	if ( DialogResult.No == result )
		e.Cancel = true;

}
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, 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