BobBarker_99
asked on
VB.net Events and Databinding
I've posted my code below. I have 2 combo boxes (cbo1 and cbo2)
When the user selects a value from cbo1, and changes focus, I want to set the value of cbo2 based on the selected value of cbo1.
The fetchList call works fine, it returns the selected list.
Here is the problem. When I select an item from cbo1, and then cause it to lose focus, the below function is called, BUT cbo2 is blank. If i select the same item again (from cbo1) and lose focus again, cbo2 is then filled properly.
Can anyone point out what I'm doing wrong?
When the user selects a value from cbo1, and changes focus, I want to set the value of cbo2 based on the selected value of cbo1.
The fetchList call works fine, it returns the selected list.
Here is the problem. When I select an item from cbo1, and then cause it to lose focus, the below function is called, BUT cbo2 is blank. If i select the same item again (from cbo1) and lose focus again, cbo2 is then filled properly.
Can anyone point out what I'm doing wrong?
Private Sub cbo1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbo1.LostFocus
If cbo1.SelectedValue Is Nothing Then Exit Sub
cbo2.DisplayMember = "DisplayString"
cbo2.ValueMember = "Value"
cbo2.DataSource = myClass.fetchList(cbo1.SelectedValue)
End Sub
I think using the SelectedIndexChanged event may help.
ASKER
I have tried setting a breakpoint. The selected value is as expected, but the second combo box does not populate.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Found it. It was returing results, but different results the first and second time through. Tracked it down, the cbo1.selectedValue wasnt what I expected teh first time through.
and see the value of cbo1.SelectedValue when the first time it is not being populated...
Could be that value is being not set for some reason ...