Filter BindingSource to show only datarows containing errors
-
Can anyone give advice on how to do this? I am using a DeveloperExpress Grid linked to a BindingSource. I import data into the bindingsource from a flat file then perform various checks to ensure the data is valid. If not, I set a column error for the row - as follows... if (view.GetRowCellValue(intRow, "intX") == null || Convert.ToDouble(view.GetRowCellValue(intRow, "intX")) == (double)0.00) { dr.SetColumnError("intX", String.Format("{0}: Missing value.", view.Columns["intX"].Caption)); } I have a button on the form to allow the user to filter the grid so that the grid will hide all valid rows to allow them to concentrate on fixing the invalid rows. Can someone tell me how to apply a filter to the binding source to only show those rows with one or more column errors? Many Thanks
-
Can anyone give advice on how to do this? I am using a DeveloperExpress Grid linked to a BindingSource. I import data into the bindingsource from a flat file then perform various checks to ensure the data is valid. If not, I set a column error for the row - as follows... if (view.GetRowCellValue(intRow, "intX") == null || Convert.ToDouble(view.GetRowCellValue(intRow, "intX")) == (double)0.00) { dr.SetColumnError("intX", String.Format("{0}: Missing value.", view.Columns["intX"].Caption)); } I have a button on the form to allow the user to filter the grid so that the grid will hide all valid rows to allow them to concentrate on fixing the invalid rows. Can someone tell me how to apply a filter to the binding source to only show those rows with one or more column errors? Many Thanks
Something like:
bindingSource1.Filter = "intX == null || intX == 0.00";
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
Something like:
bindingSource1.Filter = "intX == null || intX == 0.00";
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
Henry, Thanks for the reply. I realise I can do that - the problem I have is that there is far more to the error checking than the small snippet I posted and it will not be feasible to do it this way. I could put in a dummy column and set the value to 1 within my error checking code on finding an error and filter on the dummy column = 1. However, I was hoping there was some way I could get a collection of the rows containing an error and use that to filter eg = extract all the ids of the rows with one or more errors into an array then convert that into a filter string... ID = id1 or ID = ID2...
-
Henry, Thanks for the reply. I realise I can do that - the problem I have is that there is far more to the error checking than the small snippet I posted and it will not be feasible to do it this way. I could put in a dummy column and set the value to 1 within my error checking code on finding an error and filter on the dummy column = 1. However, I was hoping there was some way I could get a collection of the rows containing an error and use that to filter eg = extract all the ids of the rows with one or more errors into an array then convert that into a filter string... ID = id1 or ID = ID2...
Well in a .NET DataGridView you could iterate over the DataGridRowCollection and do that. I would assume the DevExpress version has the same functionality. Whether that is practical depends on the number of rows involved, from a time point of view.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
Well in a .NET DataGridView you could iterate over the DataGridRowCollection and do that. I would assume the DevExpress version has the same functionality. Whether that is practical depends on the number of rows involved, from a time point of view.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
Hi Henry - that's the approach I've now gone for... string strFilterString = ""; sp00134BindingSource.Filter = ""; // Clear any Prior Filter // foreach (DataRow dr in this.dataSet_AT.sp00134.Rows) { if (dr.HasErrors) strFilterString += " or ID = '" + dr["ID"].ToString() + "'" ?? String.Empty; } if (strFilterString.Length > 4) strFilterString = strFilterString.Remove(0, 4); // Remove initial " or " clause // if (strFilterString == String.Empty) return; try { sp00134BindingSource.Filter = strFilterString; } catch (Exception Ex) { ..... Thanks for the pointer. :)