|
-
Jul 17th, 2008, 04:14 PM
#1
Thread Starter
Fanatic Member
[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
-
Jul 17th, 2008, 04:33 PM
#2
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")
-
Jul 18th, 2008, 01:56 AM
#3
Thread Starter
Fanatic Member
Re: [02/03] Simple combobox question
Oh, sorry how would I empty the list in the combobox?
-
Jul 18th, 2008, 03:38 AM
#4
Re: [02/03] Simple combobox question
vb Code:
Me.ComboBox1.Items.Clear()
-
Jul 18th, 2008, 05:13 AM
#5
Thread Starter
Fanatic Member
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?
-
Jul 18th, 2008, 05:58 AM
#6
Member
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.
Last edited by Daarklord; Jul 18th, 2008 at 06:02 AM.
0xABADA55D00D
-
Jul 18th, 2008, 06:45 AM
#7
Thread Starter
Fanatic Member
Re: [02/03] Simple combobox question
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|