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