Infragistics(R) NetAdvantage(R) Windows Forms
BeforeRowInsertEventHandler Delegate
See Also  Example E-mail your feedback on this topic.
Infragistics.Win.UltraWinGrid Namespace : BeforeRowInsertEventHandler Delegate

sender
e
delegate for handling event that is fired before a row is being inserted

Syntax

Visual Basic (Declaration) 
Public Delegate Sub BeforeRowInsertEventHandler( _
   ByVal sender As Object, _
   ByVal e As BeforeRowInsertEventArgs _
) 
C# 
public delegate void BeforeRowInsertEventHandler( 
   object sender,
   BeforeRowInsertEventArgs e
)

Parameters

sender
e

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.

Visual BasicCopy Code
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
C#Copy Code
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;

}

See Also