Solved

VB.net Events and Databinding

Posted on 2009-07-06
6
198 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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 …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

705 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

19 Experts available now in Live!

Get 1:1 Help Now