Version

MaxRows Property

Gets/sets the maximum number of rows allowed in the band. This value is inclusive. The default is practical infinity (Int32.MaxValue).
Syntax
'Declaration
 
Public Property MaxRows As Integer
public int MaxRows {get; set;}
Remarks

MaxRows and MinRows will prevent the user from adding or removing rows if the RowsCollection will violate the MaxRows and MinRows constrants. These properties do not control what the data source can contain. It only controls whether the user is allowed to add or remove rows beyond a certain point.

Example
This snippet demonstrates how the number of rows allowed in a Band can be restricted. It also demonstrates how to inform the users when they attempt to delete too many rows.

Private Sub SetupGrid()
   ' Make sure that the user can add and delete rows from the grid.
   '
   Me.ultraGrid1.DisplayLayout.Override.AllowAddNew = AllowAddNew.TemplateOnBottom
   Me.ultraGrid1.DisplayLayout.Override.AllowDelete = DefaultableBoolean.True
   
   ' Make sure that the row selectors are displayed so that it is easy to delete rows.
   '
   Me.ultraGrid1.DisplayLayout.Override.RowSelectors = DefaultableBoolean.True
   
   ' Set the "EmergencyContacts" band to require that each row collection have between 1 and 3 rows.
   '
   Me.ultraGrid1.DisplayLayout.Bands("EmergencyContacts").MinRows = 1
   Me.ultraGrid1.DisplayLayout.Bands("EmergencyContacts").MaxRows = 3
End Sub


Private Sub ultraGrid1_Error(sender As Object, e As Infragistics.Win.UltraWinGrid.ErrorEventArgs) Handles Me.ultraGrid1.Error
   ' If the source of the error is 'RowDelete' and the Exception property is Nothing then the reason
   ' that this event fired was due to an attempt to violate the MinRows constraint.  The Exception
   ' property will be Nothing in this situation because no exception was thrown to cause this error, 
   ' but the grid's internal logic detected the error.  If the Exception property was not Nothing then
   ' that would indicate that data source threw an exception when the row was being deleted.
   '
   If e.DataErrorInfo.Source = DataErrorSource.RowDelete And e.DataErrorInfo.Exception Is Nothing Then
      MessageBox.Show("Each employee must have at least one emergency contact.", "Cannot Delete All Rows", MessageBoxButtons.OK, MessageBoxIcon.Information)
   End If
End Sub
private void SetupGrid()
{
	// Make sure that the user can add and delete rows from the grid.
	//
	this.ultraGrid1.DisplayLayout.Override.AllowAddNew = AllowAddNew.TemplateOnBottom;
	this.ultraGrid1.DisplayLayout.Override.AllowDelete = DefaultableBoolean.True;

	// Make sure that the row selectors are displayed so that it is easy to delete rows.
	//
	this.ultraGrid1.DisplayLayout.Override.RowSelectors = DefaultableBoolean.True;

	// Set the "EmergencyContacts" band to require that each row collection have between 1 and 3 rows.
	//
	this.ultraGrid1.DisplayLayout.Bands["EmergencyContacts"].MinRows = 1;
	this.ultraGrid1.DisplayLayout.Bands["EmergencyContacts"].MaxRows = 3;	
}

private void ultraGrid1_Error(object sender, Infragistics.Win.UltraWinGrid.ErrorEventArgs e)
{	
	// If the source of the error is 'RowDelete' and the Exception property is null then the reason
	// that this event fired was due to an attempt to violate the MinRows constraint.  The Exception
	// property will be null in this situation because no exception was thrown to cause this error, 
	// but the grid's internal logic detected the error.  If the Exception property was not null then
	// that would indicate that data source threw an exception when the row was being deleted.
	//
	if( e.DataErrorInfo.Source == DataErrorSource.RowDelete && e.DataErrorInfo.Exception == null )
	{
		MessageBox.Show( 
			"Each employee must have at least one emergency contact.", 
			"Cannot Delete All Rows",
			MessageBoxButtons.OK, 
			MessageBoxIcon.Information );
	}
}
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