Solved

VB.net Events and Databinding

Posted on 2009-07-06
6
199 Views
Last Modified: 2012-05-07
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?


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

Open in new window

0
Comment
Question by:BobBarker_99
6 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 24789557
set breakpoint at line: If cbo1.SelectedValue Is Nothing Then Exit Sub
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 ...
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 24790732
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24793769
I think using the SelectedIndexChanged event may help.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:BobBarker_99
ID: 24793795
I have tried setting a breakpoint.  The selected value is as expected, but the second combo box does not populate.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 24793887
Are you sure the fetchlist does return results? Set a breakpoint in that function to see what it is returning.
0
 

Author Closing Comment

by:BobBarker_99
ID: 31600373
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now