This is a migrated thread and some comments may be shown as answers.

Index out of range error

5 Answers 268 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike Dennis
Top achievements
Rank 1
Mike Dennis asked on 11 Apr 2008, 04:32 PM
I have a grid, which has all the rows so that they always stay in edit mode.  I posted a few times before about it, and I have since switched it to using the Prometheus version.  My problem may have existed before though.  The grid was originally designed to have a fake row for inserting, although that has been taken out of the grid.  In the ItemCommand event, I check for changed rows, and any rows that have changed are updated using the PerformUpdate function with suppressing the Rebind.  My problem is that I have a field that if it is 0, I need the row to be deleted.  I do this using the same stored procedure and code for the update.  If I have under the maximum number of rows for that page, and I delete more that one row (including the last row), I get an Index out of range error.  Is there a certain setting I need to use?  I tried dividing this into different parts, so the deletes get done later, and rebinding at different times.  No matter what I do it works fine until it gets to the last row, then fails.  When I do just the last row, it works fine. 

5 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 14 Apr 2008, 02:35 PM
Hi Mike,

As I'm not sure what exacly your scenario is, it will be highly appriciated if you can sent us (attached to a formal support ticket) a small working example which reproduces the unwanted behavior. We will investigate the issue you are facing and give you a more to-the-point answer.

All the best,
Rosen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mike Dennis
Top achievements
Rank 1
answered on 14 Apr 2008, 04:54 PM
Rosen,

I think I know what is causing the problem.  Hopefully there is a work around for this.  On the ItemCommand event, I use foreach to get all the EditItems.  I pass each GridEditableItem to a private function that determines if the row changed.  If it has, I use PerformUpdate to suppress the Rebind.  If a row has been changed, I Rebind the grid.  My problem is comming from how the grid handles the items.  As I described before, 0 should cause a row to be deleted, but the wrong rows are being deleted.  If I want to delete rows 3 and 5, rows 3 and 6 are deleted because once row 3 is removed, the items get moved up.  I only recieved that error in that one case, but I noticed that I had that problem all the time.  Is there something I need to do to make sure that the rows I want to delete are the rows that are deleted, even if a row before that has been deleted?

Mike
0
Rosen
Telerik team
answered on 16 Apr 2008, 12:17 PM
Hi Mike Dennis,

Are you using items indexes or DataKeyValues? Information on how to perform batch updates can be found in online documentation here.

If you continue to experience difficulties please provide us with a small working project where this behavior can be observed.

Regards,
Rosen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mike Dennis
Top achievements
Rank 1
answered on 16 Apr 2008, 01:04 PM
Rosen,

I am using one DataKeyValue.  I don't want all the rows to be updated, only those that change, so I am using the UpdateEdited command.  To make sure that enough information is there to do the update, I have a function that makes sure each of those should be updated.  I was able to get it working by checking if the rows will be updated or deleted, then doing the update if an update will happen, and if delete will happen instead, the index is stored in a List.  Those indexes are then used to delete those rows, but adjustments are made to account for the number of rows already deleted.  After that I have it insert if there is enough information for that, and anywhere from 0 to 31 items are then added.  It seems to work fine, although it would be nice to be able to get a GridEditableItem from the DataKey so that I don't have to adjust the index to fix that.

Mike
0
Rosen
Telerik team
answered on 18 Apr 2008, 02:47 PM
Hello Mike,

I attached a simple test project that tries to replicate the case described by you. Can you please check it and see if I'm leaving something obvious out?
If you continue to experience difficulties feel free to modify the project thus making the error surface and send it to us (attached to a formal ticket). Thus we will do our best to give you more accurate explanation/solution.

Best regards,
Rosen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Mike Dennis
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Mike Dennis
Top achievements
Rank 1
Share this question
or