differing combo box values

callraheel

Well-known member
Joined
Dec 12, 2004
Messages
65
Location
London,UK
Programming Experience
1-3
Hey
I have 4 combo boxes on a form and there are more then 4 items in all of them
now i want that when one item is selected in a combo box then it should be unique as compared to 4 combo boxes...
Now let me be a bit clear
suppose in 1st combo box we have
boy,girl,son,daughter..
now when i select in 1st box : girl
then in 2nd,3rd and fourth : boy, son and daughter should be selected

I mean all boxes have same 4 values but when one is changed all should be changed and produce unqiue values themselves..

I hope now you can understand it well

Waiting for response.

Regards
 
VB.NET:
Expand Collapse Copy
[size=2][color=#0000ff]Private [/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] Form1_Load([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sender [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Object, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.EventArgs) [/size][size=2][color=#0000ff]Handles [/color][/size][size=2][color=#0000ff]MyBase[/color][/size][size=2].Load
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] i [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Integer
 
[/color][/size][size=2][color=#0000ff]For[/color][/size][size=2] i = 1 [/size][size=2][color=#0000ff]To[/color][/size][size=2] 4
 
ComboBox1.Items.Add("Item " & i)
 
ComboBox2.Items.Add("Item " & i)
 
ComboBox3.Items.Add("Item " & i)
 
ComboBox4.Items.Add("Item " & i)
 
[/size][size=2][color=#0000ff]Next
 
[/color][/size][size=2][color=#0000ff]End [/color][/size][size=2][color=#0000ff]Sub
 
[/color][/size][size=2][color=#0000ff]Private [/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] ComboBox1_SelectedIndexChanged([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sender [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Object, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.EventArgs) [/size][size=2][color=#0000ff]Handles[/color][/size][size=2] ComboBox1.SelectedIndexChanged
 
[size=2]ComboBox2.SelectedIndex = ComboBox1.SelectedIndex + 1
 
ComboBox3.SelectedIndex = ComboBox1.SelectedIndex + 2
 
ComboBox4.SelectedIndex = ComboBox1.SelectedIndex + 3
 
[/size]
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Sub[/color][/size]
[size=2][color=#0000ff]
[/color][/size]


Cheers ;)

 
Well i think now i should tell you the whole thing because this is not solving my problem...
I have a table in database name 'subjects'.
Now in all 4 combo boxes i add a range of all subjects from this table...
And there can be any number of subjects in table... but i can get the number through array length.
Now if the user select a subject in a combo box then THAT SUBJECT MUST NOT BE IN ANY OF OTHER COMBO BOX... that is my requirement..
Waiting for response.
Regards
 
ComboBox2.SelectedIndex = ComboBox1.SelectedIndex + 1

ComboBox3.SelectedIndex = ComboBox1.SelectedIndex + 2

ComboBox4.SelectedIndex = ComboBox1.SelectedIndex + 3


this will always return different index for rest of the combos but however if you select i.e. 4th item it will go out of range ... will be thrown an exception ... so forget about this.
I think the best for you will be using of an If statement ... :)
for instance check the selectedindex of first combo and then set a different selected index for rest of the combos ... there is not better solution. Maybe i thought about random but however that is also bad idea.

Cheers ;)
 
Well kulrom thanx for replying...i have sort it out by using variables....for instance like the following but still it do not change values like i want but its ok for validation

Dim subArray(3) As String, i As Integer, j As Integer

subArray(0) = cmbSubject1.SelectedItem

subArray(1) = cmbSubject2.SelectedItem

subArray(2) = cmbSubject3.SelectedItem

subArray(3) = cmbSubject4.SelectedItem

For i = 0 To 3

For j = 0 To 3

If i <> j Then

If subArray(i) = subArray(j) Then

Msgbox("Duplicate Subject Found", "Subject " & (i + 1).ToString & " and Subject " & (j + 1).ToString & " are found to be duplicate", NETXP.Components.NotifyInfoFlags.Error, 1000)

Exit Sub
End If

End If

Next

Next

I wrote the code for other who may find same problem...

Anyways thanx a lot!

Cheers

 
Back
Top