Solved

VB.net Events and Databinding

Posted on 2009-07-06
6
201 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 70

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Change Locale for Crystal Reports Dynamically in VB.Net 2010 Winforms. 3 36
Access Schema 6 45
ModalPopup  question 22 40
vb.net background worker crossthread 11 30
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

696 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