C
Chris Mayers
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.
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.