Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Filter BindingSource to show only datarows containing errors

Filter BindingSource to show only datarows containing errors

Scheduled Pinned Locked Moved C#
csswpfwcfhelptutorial
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MarkB123
    wrote on last edited by
    #1

    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

    H 1 Reply Last reply
    0
    • M MarkB123

      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

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      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.”

      M 1 Reply Last reply
      0
      • H Henry Minute

        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.”

        M Offline
        M Offline
        MarkB123
        wrote on last edited by
        #3

        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...

        H 1 Reply Last reply
        0
        • M MarkB123

          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...

          H Offline
          H Offline
          Henry Minute
          wrote on last edited by
          #4

          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.”

          M 1 Reply Last reply
          0
          • H Henry Minute

            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.”

            M Offline
            M Offline
            MarkB123
            wrote on last edited by
            #5

            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. :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups