[VB.NET] Best way of doing this?

Soldato
Joined
12 Jun 2005
Posts
5,361
Hi there,

I have 5 drop down boxes all with the same 10 items in them.

What i want to happen is that when you select one of the items in one of the drop down boxes, it doesn't have it on the list of the other drop down boxes. And if you select something else tehn the thing you selected first time in in the lists and the thing that is currently selected isn't there.

And this is the same for all the drop down boxes.

Thanks.
 
Erm... First question, why? :)

Without thinking to much into it I would first add all 10 items to a collection, this was you always have a list of the full 10 items that does not get modified.

On load populate the collection, then you ComboBoxes using the data in the collection. When an item is selected, clear the other comboboxes and re-populate them using the collection, only checking each time if the value match the selected value of the combobox.

Hope this makes sense.

Someone else probably has a much better solution. :)

TrUz
 
If you're trying to do what I think you're trying to do then surely a checked listbox would be a much better idea?

Wouldn't take too much effort to restrict a user to only being able to select 5 items in there.
 
First to answer why:

Cause i need to be able to refer to the value in each combo box so i can assign it a value based on whats selected in another combo box by it.

With check boxes i can't do that and make it user friendly.

I see what you are getting at with the collection thing and will give that a go
 
TrUz said:

Tried this and because after you have reconstructed the list, you have to set the selected values of the drop down boxes that were already selected it goes in a loop and doesn't stop.

How do i avoid this.

Edit:

I think i see what you have to do. Some kind of Latch
 
Last edited:
How about just leaving all the items in the ComboBoxes and just validating the selections afterwards? Make sure that none of the SelectedIndexes are the same?

Or instead of validating at the end you could validate after each selection in the SelectedIndexChanged event handler?

EDIT: Why not a CheckedListBox? It does not get much more user friendly than that? You can see all available options straight away and only has to make 5 clicks instead of 10? ;)

TrUz
 
Hi there,

Thanks for your reply, I have done what i originally wanted (thanks to your help).

Basically i have five sets of two drop box boxes and they are linked to each other.

So tha value selected on the left will be assigned to the value on the right.

Maybe this diagram will help:

3b88bfa030_Untitled1png.png


If I did it with a drop down check box, it wouldnt have the same effect. Because I and the user will need to know what is linked to what

I would prefer to do it so it updates the lists rather than any validating.

Thanks for your help!!!
 
We was actually refering to a CheckedListBox. But if you have done it now, no worries. :)

TrUz
 
New Question

Basically,

I have my five drop down boxes with the values in them.

I need to work out every possible combination (sum of the drop down boxes) and add it to a list.

First part would be:

1
2
3
4
5

Second Part:

1,2
1,3
1,4
1,5
2,3
2,4
2,5
3,4
3,5
4,5

Third Part:

1,2,3
1,2,4
1,2,5
1,3,4
1,3,5
1,4,5
2,3,4
2,3,5
2,4,5
3,4,5

Fourth Part:

1,2,3,4
1,2,3,5
1,2,4,5
1,3,4,5
2,3,4,5

Fifth Part:

1,2,3,4,5

Total Number of Combitionations:

31 (if my maths is correcT)

key:

1 = Drop Down Box 1
2 = Drop Down Box 2
3 = Drop Down Box 3
4 = Drop Down Box 4
5 = Drop Down Box 5

Is there a more efficient way than manually typing every combination?

Thanks
 
Last edited:
Further expalination:

Basically I want to shorten this, is there a way?

Code:
        Dim d1, d2, d3, d4, d5 As Integer
        Dim sComb As List(Of Integer)

        d1 = Val(S1.SelectedItem)
        d2 = Val(S2.SelectedItem)
        d3 = Val(S3.SelectedItem)
        d4 = Val(S4.SelectedItem)
        d5 = Val(S5.SelectedItem)
            
        sComb.Add(d1)
        sComb.Add(d2)
        sComb.Add(d3)
        sComb.Add(d4)
        sComb.Add(d5)
        sComb.Add(d1 + d2)
        sComb.Add(d1 + d3)
        sComb.Add(d1 + d4)
        sComb.Add(d1 + d5)
        sComb.Add(d2 + d3)
        sComb.Add(d2 + d4)
        sComb.Add(d2 + d5)
        sComb.Add(d3 + d4)
        sComb.Add(d3 + d5)
        sComb.Add(d4 + d5)
        sComb.Add(d1 + d2 + d3)
        sComb.Add(d1 + d2 + d4)
        sComb.Add(d1 + d2 + d5)
        sComb.Add(d1 + d3 + d4)
        sComb.Add(d1 + d3 + d5)
        sComb.Add(d1 + d4 + d5)
        sComb.Add(d2 + d3 + d4)
        sComb.Add(d2 + d3 + d5)
        sComb.Add(d2 + d4 + d5)
        sComb.Add(d3 + d4 + d5)
        sComb.Add(d1 + d2 + d3 + d4)
        sComb.Add(d1 + d2 + d3 + d5)
        sComb.Add(d1 + d2 + d4 + d5)
        sComb.Add(d1 + d3 + d4 + d5)
        sComb.Add(d2 + d3 + d4 + d5)
        sComb.Add(d1 + d2 + d3 + d4 + d5)
 
You know, even after reading all of your posts I'm not quite sure what you actually wanted to achieve here.
I'm fairly sure that you've made a lot of unnecessary extra work for yourself though.

Do you have a code sample of your finished product to have a look at?
 
Back
Top Bottom