Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Pro Visual Basic 2005
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Pro Visual Basic 2005 For advanced Visual Basic coders working in version 2005. Beginning-level questions will be redirected to other forums, including Beginning VB 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro Visual Basic 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 22nd, 2007, 08:05 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Location: Wellington, FL , USA.
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default SelectedValueChanged event is giving me a headache

I am running into an issue that I would have thought wouldn't be difficult, but for some reason I am drawing a blank, and frankly am embarassed to ask (must be all the eggnog...).

I have a form with a button and two list boxes. The button populates the first list box with data.

On the SelectedValueChanged event of the first list box I have code which populates the second list box.

The problem I am running in to is that the code in the SelectedValueChanged event of the first list box is being fired as soon as I set its DataSource.

In the click event of the button, I create and populate a Dataset and set that as the data source of the first list box. In the SelectedValueChanged of the first list box, I have code similar to the following:

If Me.listbox1.SelectedIndex > -1 Then
   id = directcast(me.listbox1.selectedvalue, integer)
   'do other stuff
end if

The problem I am having is that because the SelectedValueChanged is being called as soon as I set the DataSource, the SelectedValue has a value of System.Data.DataRowView, and therefore the setting of my id variable is blowing.

What am I doing wrong? Any insight is greatly appreciated.


========================
Scott Klein
Author of:
Professional SQL Server 2005 XML
Professional WCF Programming: .NET Development with the Windows Communication Foundation
Professional LINQ
========================
__________________
========================
Scott Klein
Author of:
Professional SQL Server 2005 XML
Professional WCF Programming: .NET Development with the Windows Communication Foundation
Professional LINQ
========================
Reply With Quote
  #2 (permalink)  
Old January 2nd, 2008, 05:46 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

In the routine that is populating the 1st listbox, set a module/class-scope boolean to True:
Code:
    bUpdatingList = True
In the routines that are running when they ought not, add
Code:
    If bUpdatingList = True Then Exit Sub
Of course, when the list gets filled, the first element becomes current.††That represents a change of SelectedValue, which in turn raises the event...

Or am I missing the specifics of the problem?

(Had to edit to fix spelling...:()
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Combobox SelectedValueChanged Event Frankvk Pro VB.NET 2002/2003 2 March 12th, 2005 06:28 PM
iif Statement giving me a headache! MrMacca BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 January 7th, 2005 04:49 AM
Giving a program a 'name' Badman3k VB.NET 2002/2003 Basics 2 September 12th, 2004 09:57 PM
XML, Sockets, Streams and a headache owain General .NET 4 September 8th, 2004 04:53 AM
Subform Headache GregoryHu Access VBA 0 July 9th, 2004 10:20 AM



All times are GMT -4. The time now is 08:14 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.