LAST Row Delete - Problem

Mohsin

New member
Joined
Jun 19, 2007
Messages
2
Programming Experience
1-3
Hi Guys, I have a silly problem. Im binding my dataGridView to my xml source. It is loading and getting binded. All this is fine. Now once the data is loaded im trying to delete the last row and update my xml, but it gives the error that the last low does not exist. this happens only if i delete the last row only, if i delete any row in the middle, it deletes the row from the dataTable and then modifies the XML. But the problem is only when i delete the last row. Below is my code for deleting the row.


ds.Tables(0).Rows.RemoveAt((e.Row.Index))
ds.Tables(0).WriteXml(Application.StartupPath & "\data.xml")

When i run my program and delete the Last row, it gives error (but the xml file is modified). And then when I close the program and run it again , I get the data loaded in the grid with the last row deleted.

ANY HELP PLZZZZ!!!!
 
what is the exception that it is giving you?

and which of those lines is the error coming from?

and what control are you using to display the data. I am assuming some sort of datagrid.

But based on what you said that tells me that the data is actually being modified but you are most likely receiving an error when actually removing it from the control.

If you could tell me what type of exception it is throwing and get the few lines of code that it blows up on I could probably figure out a solution for you.
 
Hi Guys, I have a silly problem. Im binding my dataGridView to my xml source. It is loading and getting binded. All this is fine. Now once the data is loaded im trying to delete the last row and update my xml, but it gives the error that the last low does not exist. this happens only if i delete the last row only, if i delete any row in the middle, it deletes the row from the dataTable and then modifies the XML. But the problem is only when i delete the last row. Below is my code for deleting the row.

Just out of curiousity, are you assuming that a row collection of 100 rows has a last row that is index 100? I think you might find it's 0-99, hence row 100 doesnt exist! The last entry in any collection is: collection.Length - 1
 
Back
Top