Solved

VB.net Events and Databinding

Posted on 2009-07-06
6
202 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
Technology Partners: 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

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!

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

729 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