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. filtering of comboboxes SOLVED

filtering of comboboxes SOLVED

Scheduled Pinned Locked Moved C#
csshelptutorial
10 Posts 3 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.
  • B Offline
    B Offline
    bdeklerk
    wrote on last edited by
    #1

    Hi everyone, I would like to filter comboboxes. If I choose a certain value in one combobox, the following two comboboxes should only display the value of the first combobox or less. So lets say I choose an amount of 100 000.00 the following two comboboxes should only have 0 - 100 000.00 displaying in them. Any ideas on how to do this would be appreciated. Thanks for the help.

    P W 2 Replies Last reply
    0
    • B bdeklerk

      Hi everyone, I would like to filter comboboxes. If I choose a certain value in one combobox, the following two comboboxes should only display the value of the first combobox or less. So lets say I choose an amount of 100 000.00 the following two comboboxes should only have 0 - 100 000.00 displaying in them. Any ideas on how to do this would be appreciated. Thanks for the help.

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Please tell me you aren't planning on having 100K items in a combobox. That would present a totally unusable interface for a user.

      *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

      "Mind bleach! Send me mind bleach!" - Nagy Vilmos

      CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

      B 1 Reply Last reply
      0
      • B bdeklerk

        Hi everyone, I would like to filter comboboxes. If I choose a certain value in one combobox, the following two comboboxes should only display the value of the first combobox or less. So lets say I choose an amount of 100 000.00 the following two comboboxes should only have 0 - 100 000.00 displaying in them. Any ideas on how to do this would be appreciated. Thanks for the help.

        W Offline
        W Offline
        Wayne Gaylard
        wrote on last edited by
        #3

        How are you populating the comboboxes ? If you are really using integers as you suggest then you just need to handle the Selected Value changed event of the first combo, and then generate a List and bind that to the other 2 combos, something like this

        int uBound = firstCombo.SelectedValue;
        List intList = Enumerable.Range(0, uBound).ToList();
        secondCombo.DataSource = intList;
        thirdCombo.DataSource = intList;

        This is off the top of my head, and is untested - but you should get the gist.

        When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman

        B 1 Reply Last reply
        0
        • P Pete OHanlon

          Please tell me you aren't planning on having 100K items in a combobox. That would present a totally unusable interface for a user.

          *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

          "Mind bleach! Send me mind bleach!" - Nagy Vilmos

          CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

          B Offline
          B Offline
          bdeklerk
          wrote on last edited by
          #4

          Sorry I should have been more clear. The amounts in the comboboxes are from 0 - 200 00.00 every 10 000.00 so 0, 10 000.00, 20 000.00 etc etc. Thanks

          P 1 Reply Last reply
          0
          • W Wayne Gaylard

            How are you populating the comboboxes ? If you are really using integers as you suggest then you just need to handle the Selected Value changed event of the first combo, and then generate a List and bind that to the other 2 combos, something like this

            int uBound = firstCombo.SelectedValue;
            List intList = Enumerable.Range(0, uBound).ToList();
            secondCombo.DataSource = intList;
            thirdCombo.DataSource = intList;

            This is off the top of my head, and is untested - but you should get the gist.

            When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman

            B Offline
            B Offline
            bdeklerk
            wrote on last edited by
            #5

            Thanks for the reply. Im populating the boxes from a table in SQL.

            W 1 Reply Last reply
            0
            • B bdeklerk

              Thanks for the reply. Im populating the boxes from a table in SQL.

              W Offline
              W Offline
              Wayne Gaylard
              wrote on last edited by
              #6

              If you hold a List of all the possible values, then you can filter that list using LinQ

              decimal selectedValue = firstCombo.SelectedValue;
              List values = (from value in fullList where value <= selectedValue select value).ToList();

              and then bind values to the second and third combos. This assumes the values are decimals.

              When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman

              B 1 Reply Last reply
              0
              • B bdeklerk

                Sorry I should have been more clear. The amounts in the comboboxes are from 0 - 200 00.00 every 10 000.00 so 0, 10 000.00, 20 000.00 etc etc. Thanks

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #7

                Ah good. For a moment you had me worried. You'd be surprised how many times we see people wanting insane amounts of data in there. As you haven't said which technology you are using, I am going to assume you want Windows Forms and would look to implement this using LINQ. Basically, you capture the selection changed in the first combobox and use that to change your DataSource on the second one using a query like this (for this example I'm assuming you've prepopulated an array called filterValues with your values from 0 to 200000):

                secondComboBox.DataSource = (from p in filterValues
                where p <= firstComboValue
                select p).ToList();

                *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

                "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                1 Reply Last reply
                0
                • W Wayne Gaylard

                  If you hold a List of all the possible values, then you can filter that list using LinQ

                  decimal selectedValue = firstCombo.SelectedValue;
                  List values = (from value in fullList where value <= selectedValue select value).ToList();

                  and then bind values to the second and third combos. This assumes the values are decimals.

                  When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman

                  B Offline
                  B Offline
                  bdeklerk
                  wrote on last edited by
                  #8

                  That works great. Thanks for the help guys and special thanks to Wayne Gaylard. :-D

                  B 1 Reply Last reply
                  0
                  • B bdeklerk

                    That works great. Thanks for the help guys and special thanks to Wayne Gaylard. :-D

                    B Offline
                    B Offline
                    bdeklerk
                    wrote on last edited by
                    #9

                    How do i close this thread now guys?

                    W 1 Reply Last reply
                    0
                    • B bdeklerk

                      How do i close this thread now guys?

                      W Offline
                      W Offline
                      Wayne Gaylard
                      wrote on last edited by
                      #10

                      Just modify your subject line by adding SOLVED on the end. The thread will remain for ever more in the annals of history.

                      When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman

                      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