[RESOLVED] [02/03] Simple combobox question
Hi people,
I was hoping someone could help me out please, the question is really simple.
I have 2 forms, on form 1 I have 2 buttons which both open up form 2. What I want is when button 1 opens up form2, I want to display text 1,3 and 4. And when button 2 opens up form 2 I want to display only text 2 in the combobox.
In the combobox collection I have the following text one, two, three, four.
So far I have the following coding which doesn't do much apart from display two in the combobox when button 2 is selected:
Code:
'button1
frm2.ShowDialog()
frm2.Dispose()
'button2
frm2.Tag = "Two"
frm2.ShowDialog()
frm2.Dispose()
frm2 load event'
If Me.Tag = "Two" Then
cmbnum.SelectedIndex = 1
cmbnum.Text = "Two"
Any help please? thanks
Re: [02/03] Simple combobox question
Remove all the text from the combobox, so the list is empty.
Then, if Tag = "Two"
cmbnum.Items.Add("Two")
Re: [02/03] Simple combobox question
Oh, sorry how would I empty the list in the combobox?
Re: [02/03] Simple combobox question
vb Code:
Me.ComboBox1.Items.Clear()
Re: [02/03] Simple combobox question
Oh ok, So far I deleted the items in the cmbnum collection (one, two, three, four as the text is going to be hard coded.) Then I have the following coding on the form2 load event:
Code:
Me.cmbnum.Items.Clear()
If Me.Tag = "Two" Then
cmbnum.Text = "Two"
If cmbnum.Items.Count > -1 Then cmbnum.SelectedIndex = 0
Else
Me.cmbnum.Items.Add("One")
Me.cmbnum.Items.Add("Three")
Me.cmbnum.Items.Add("Four")
If cmbnum.Items.Count > -1 Then cmbstatus.SelectedIndex = 0
End If
Now when button one opens up form 2 it shows the correct data in the combobox, however when button two opens up form 2 it breaks on the following line:
cmbnum.SelectedIndex = 0
Additional information: Specified argument was out of the range of valid values.
Any help please?
Re: [02/03] Simple combobox question
You did not add "Two" to the combox when button 2 is clicked. Setting the text does not add to the list of items.
Code:
Me.cmbnum.Items.Clear()
If Me.Tag = "Two" Then
cmbnum.Text = "Two"
Me.cmbnum.Items.Add("Two")
If cmbnum.Items.Count > -1 Then cmbnum.SelectedIndex = 0
Else
Me.cmbnum.Items.Add("One")
Me.cmbnum.Items.Add("Three")
Me.cmbnum.Items.Add("Four")
If cmbnum.Items.Count > -1 Then cmbstatus.SelectedIndex = 0
End If
Also, your If cmbnum.Items.Count > -1 doesn't check for empty list, in which case the count would be 0.
Re: [02/03] Simple combobox question