Index Error

Hi All!

I have a set of record in my griddataboundgrid
When i delete any record in the gridits show Error
message like..

"Index was out of range. Must be non-negative and less than the size of the collection.Parameter name: index"

When i trace through my code it catch error in
grid.CommitChanges line.

Can u suggest me the solution please..

Regards

Leema



4 Replies

AD Administrator Syncfusion Team January 12, 2007 11:17 AM UTC

Hi Leema,

I think the record you are trying to delete is not there in the underlying datasource. Please try this code to delete the record from grid.

int rowIndex = 1;
if( this.gridDataBoundGrid1.Model.RowCount -1 > rowIndex )
this.gridDataBoundGrid1.DeleteRecordsAtRowIndex(rowIndex,rowIndex);

Best Regards,
Haneef


AD Administrator Syncfusion Team January 12, 2007 11:30 AM UTC

Hi,
Error is coming in "PrepareViewStyleInfo", When i delete.

In "PrepareViewStyleInfo" i have written like this. My grid display is in multiline view [1 datarow equal 2 lines in grid ]
CurrencyManager cm = (CurrencyManager)this.BindingContext[this.DataSource];
CLIBidSheet aBidSheet = (CLIBidSheet)(cm.List);
CLIBidItem dr = (CLIBidItem)aBidSheet[((e.RowIndex-2) / 2)];

can you suggest me a solution.


AD Administrator Syncfusion Team January 12, 2007 11:47 AM UTC

Hi Leema,

Could you please use this code snippet to access the CLIBidItem from CLIBidSheet in a PrepareViewStyleInfo event.

CurrencyManager cm = (CurrencyManager)this.BindingContext[this.DataSource];
CLIBidSheet aBidSheet = (CLIBidSheet)(cm.List);

int index = (int)((e.RowIndex-2) / 2);
if( index >= 0 && index < cm.List.Count)
{
CLIBidItem dr = (CLIBidItem)aBidSheet[index];
//Your related code here
}

Let me know if this helps.

Best Regards,
Haneef


AD Administrator Syncfusion Team January 12, 2007 12:06 PM UTC

Thanks,
Its working.

Loader.
Up arrow icon