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

Event parameters used for the BeforeRowInsert event

Syntax

Visual Basic (Declaration) 
Public Class BeforeRowInsertEventArgs 
   Inherits System.ComponentModel.CancelEventArgs
C# 
public class BeforeRowInsertEventArgs : System.ComponentModel.CancelEventArgs 

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