-
Oct 3rd, 2011, 05:05 PM
#1
Thread Starter
Lively Member
Combo Box Events
I have combobox1 and combobox2, both databound.
Box2 will be a selected value that changes based off box1 selection.
Code:
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
If ComboBox2.Text = "1" Then
Form1.show()
ElseIf ComboBox2.Text = "2" Then
Form2.show()
End If
End Sub
Problem is, when you select items from Box1 and no changes are made to Box2 like say it stays at "2" then it never fires the event. Also, if i do it to the Box1 event, it goes off what is in Box2 before it changed, not what it changed to.
How can I get it to trigger the event (or what event should I use) if Box2 value doesn't change???
-
Oct 3rd, 2011, 05:34 PM
#2
Addicted Member
Re: Combo Box Events
I tried out a workaround - hope it helps
Code:
Private Sub ComboBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedValueChanged
ComboBox2.Text = ComboBox1.Text
If ComboBox2.Text = "1" Then
Form1.Show
ElseIf ComboBox2.Text = "2" Then
Form2.Show
End If
End Sub
-
Oct 3rd, 2011, 05:47 PM
#3
New Member
Re: Combo Box Events
I came up with this, just in case you do need both CBs (ComboBoxes);
vb Code:
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Me.BackColor = Color.Red Form2.BackColor = Color.Green CB1.Items.Add("1") CB1.Items.Add("2") CB2.Items.Add("1") CB2.Items.Add("2") End Sub Private Sub CB1_SelectedIndexChanged(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles CB1.SelectedIndexChanged CB2.ResetText() If CB1.SelectedIndex = 0 Then CB2.SelectedIndex = 0 Else CB2.SelectedIndex = 1 End If End Sub Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles CB2.SelectedIndexChanged If CB2.Text = "1" Then Me.Show() ElseIf CB2.Text = "2" Then Me.Hide() Form2.Show() End If End Sub End Class
-
Oct 3rd, 2011, 10:33 PM
#4
Thread Starter
Lively Member
Re: Combo Box Events
Thanks for the help so far, it's not quite working for me, I don't think I explained it very well, I was trying to keep it basic. I'm using MDI forms, they load within a parent based on CB2's text... whatever item is displayed in CB2, that's what MDIChild data entry form shows up. Right now I have the datatable.fill in the FormActivated event and the datatable.update in the FormDeactivate event. I just use bringtofront based off CB2's text. Problem is, if you select an item from CB1 and CB2 doesn't change, it doesn't fire the event to activate the page so therefore the data never gets update/filled. The form just stays there with the old data in it.
To keep it simple, lets say CB1 is names... John, Jim, Jake... (could be a hundred names)
CB2 is fruit... Apple, Orange, Banana, etc... (could be like 20 fruits)
So you select John and CB2 switches to Banana, that's what is selected and saved in the database... everytime you select John the CB2 will change to Banana until you choose a different one, and the banana form would be shown, and John's data would be loaded.
BUT, if you select Jake and it's also Banana, the event won't fire and Jakes data won't load because CB2 never changed, and John's data will still be displayed. If you had selected Jim and CB2 switches to Apple, the event fires and loads Jim's data...
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
|