Actually what I am trying to do is to give the user chance to undo changes by
calling BindingSource.CancelEdit()
And making Save button which is updating changes to the database By calling
the update Tableadaptor method so I have to call Remove or RemoveAt Or what
do u think?
To delete multiple rows in a datagridview I am using
try
{
for (int i = Main2DGrdView.SelectedCells.Count - 1; i >= 0;
i--)
{
mAIN1MAIN2RelationBindingSource.RemoveAt
(Main2DGrdView.SelectedCells[i].RowIndex);
}
}
catch (Exception ex)
{
MessageBox.Show("Deleted failed" + "\n" + ex.Message);
}
It raise the exception ArgumentOutOfRangeException
So how to force the program to only delete row and jump to next selected row
and deleted too
Thank you in advance
mmsjed
> As I see that you use a datatable: first the question, do you want to use
> remove? Remove means that it is removed from the collection, not giving the
[quoted text clipped - 24 lines]
> >
> > Thank you in advance
Cor Ligthert[MVP] - 18 Mar 2008 18:00 GMT
You have to use the delete methods which leaves the rows in the datatable
with a rowstate deleted.
When the update is done, the rows will be removed by the in the dataadapter
update build in AcceptChanges method which does that.
Cor
> Actually what I am trying to do is to give the user chance to undo changes
> by
[quoted text clipped - 58 lines]
>> >
>> > Thank you in advance
MMSJED - 18 Mar 2008 20:41 GMT
Sorry I did not get you
Please could you tell me How
Thank you in advance
mmsjed
> You have to use the delete methods which leaves the rows in the datatable
> with a rowstate deleted.
[quoted text clipped - 66 lines]
> >> >
> >> > Thank you in advance
Steve Gerrard - 19 Mar 2008 03:20 GMT
> Sorry I did not get you
> Please could you tell me How
Using RemoveAt on a BindingSource will carry the deletion through to the
underlying dataset, so there is nothing wrong with using that.
I'm not sure if CancelEdit will cancel only the last RemoveAt, or all removals.
If not, you can always do RejectChanges on the entire dataset to get an undo.
Rather than SelectedCells, you should be doing SelectedRows (still going from
Count - 1 to 0). That's why your index is going out of range.
MMSJED - 19 Mar 2008 07:03 GMT
How to fix the index is going out of range this is my main question
I believe this answer need expert
> > Sorry I did not get you
> > Please could you tell me How
[quoted text clipped - 7 lines]
> Rather than SelectedCells, you should be doing SelectedRows (still going from
> Count - 1 to 0). That's why your index is going out of range.