We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Prevent EnableAddNew from expanding GridDataBroundGrid beyond a specific number of rows

Hello,

I'm working with a GridDataBoundGrid on a windows form, which has the "EnableAddNew" property set to true, so that the grid automatically expands 1 row at a time per the user's needs. However, I don't want the grid to expand beyond 8 rows and I'm finding the logic to be a bit tricky to prevent this. Currently I have code that looks like this:

void GridSubParts_CurrentCellEditingComplete(Object sender, EventArgs e)
{
GridDataBoundGrid grid = (GridDataBoundGrid)sender;
grid.EnableAddNew = grid.Model.RowCount <= 8 ? true : false;
}

The result is once the GridDataBoundGrid control reaches 8 rows, when you click several different cells (which clicking a given cell triggers the 'cell editing') the GridDataBoundGrid will expand to 9 rows and then shrink back to 8 rows every other click.

What is the preferred way of preventing the GridDataBoundGrid from expanding beyond a specific amount of rows? Is there a maximum rows property?



1 Reply

CB Clay Burch Syncfusion Team March 16, 2010 04:34 PM UTC

There is no maximum rows proeprty for a GridDataBoundGrid.

If your datasource is some kind of IBindingList or DataView that supports a ListChanged event, then you can use that event to set the EnableAddNew property in a timely fashion.


void _ListChanged(object sender, ListChangedEventArgs e)
{
IList list = sender as IList;
if (list.Count == 8)
{
gridDataBoundGrid1.EnableAddNew = false;
}
}

Loader.
Live Chat Icon For mobile
Up arrow icon