Thanks for your suggestion. Sorry to have bothered you though!
code I published here was trying to delete the row...
PS. I did use your suggestion anyway as the DataRowView[] collection does
"Brock Allen" <ballen@NOSPAMdevelop.com> wrote in message
news:544378632500344166316288@msnews.microsoft.com...
> Well, rowIndex out of range sounds like the collection is getting
reordered
> when you delete a row. So the DataRowView internally just has a row index
> into the original collection. So when you get to a row further down in the
> collecion, then original row number the DataRowView held is no longer
valid.
> IOW, I go to row 5, say, and delete it, then I go to what used to be row
> 6, and now it's row 5 since they all got bumped up in the collection.
>
> I'd suggest getting the DataRowView.Row and then deleting that. So it
might
> mean that you'll need to do a first pass over the collection to get an
array
> of the real DataRows then delete those.
>
> -Brock
> DevelopMentor
>
http://staff.develop.com/ballen >
>
>
> > Can anyone please tell me what is wrong with the following code:
> >
> > I have a datagrid showing data from in a DataView.
> >
> > The following code snippet is supposed to delete any rows where the
> > 'LineType' column contains WD.
> >
> > The strange thing is it works sometimes (10%?) but usually I get an
> > error: 'Specified argument was out of the range of valid values.
> > Parameter name: rowIndex'
> >
> > Please no comments on my error handling, this is just to show the
> > errors I'm getting...
> >
> > DataView dv = (DataView)dataGrid1.DataSource;
> > dv.Sort = "LineType";
> > dv.AllowDelete = true;
> > DataRowView[] rowsToDelete = dv.FindRows("WD");
> > foreach(DataRowView rowToDelete in rowsToDelete)
> > {
> > try
> > {
> > rowToDelete.Delete();
> > //also tried : rowsToDelete[0].Delete();
> > }
> > catch (Exception ex)
> > {
> > MessageBox.Show(ex.Message);
> > }
> > If anyone can tell me what I'm doing wrong, even if it is simply that
> > I'm trying to do somthing you're not supposed to do, I would be most
> > grateful.
> >
> > Thanks,
> >
> > Chris.
> >
>
>
>