Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics 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 Search this Thread Display Modes
  #1 (permalink)  
Old July 12th, 2006, 11:52 AM
Friend of Wrox
Points: 2,876, Level: 22
Points: 2,876, Level: 22 Points: 2,876, Level: 22 Points: 2,876, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Denver, CO, USA.
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default Set cbo.selectedvalue using Value problem persists

I posted this question once already, but somebody responded with a solution that did not work and I suspect nobody else is bothering to look at the question because they think the problem was solved by the response. I could really use a response that actually works:

I have a combo box on a Windows form populated from a table looking something like this:

DISPLAYMEMBER VALUEMEMBER INDEX
Select Name 0 0
Name1 193 1
Name2 40 2

The user selects an Item from the cbo and the VALUE is saved to another table. When the user later edits the saved data, I want to automatically select the VALUE from the combobox to reflect the previous selection. The only way I have been able to select the item I want by VALUE is by looping and checking every VALUE to find the one I want:

For intPos As Integer = 0 To .Count - 1
  If comboBox.Item(intPos)("Value") = v_intValue Then
    comboBox.SelectedIndex = intPos

    Exit Sub
  End If
Next

It has to do this for over 40 comboboxes on the form, and as you can imagine, that's not exactly efficient. It's all the more frustrating that the ASP version of the combobox supports the Items.FindByValue method to determine the combobox index of the value in question (exactly what I want) and the windows control does not (Hello, Microsoft?!?!?!)

I've found sites claiming this will work, but it doesn't:

combobox.SelectedValue = 40

I know for a fact that VALUE 40 exists in the combobox, but if I query SelectedValue after attempting to set it, it returns NOTHING and SelectedIndex is still 0. I've also seen suggestions that I try this:

combobox.SelectedIndex = combobox.FindString("40")

But FindString appears to only search the DISPLAYMEMBER, and not VALUEMEMBER, and the code above returns -1. Another dead end.

Finally, the solution suggested to my last posting of this question does not work because the method suggested doesn't even exist:

combobox.Value = 40

This seems like a pretty common need (and it's been implemented properly in ASP). Isn't there a more efficient way of selecting a combobox item using using VALUEMEMBER in a Windows form?
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Persists.MailSender dammy Classic ASP Components 1 September 6th, 2007 01:02 PM
Need Help with DropDownList SelectedValue putputty ASP.NET 2.0 Basics 4 June 27th, 2007 11:44 AM
Unable to set SelectedValue on DropDownList jlrolin ASP.NET 2.0 Professional 0 April 13th, 2007 09:30 AM
Can't EASILY set cbo.selecteditem using VALUE Ron Howerton Visual Basic 2005 Basics 5 December 14th, 2006 04:52 PM
comboBox.SelectedValue melvik C# 1 August 19th, 2003 09:21 AM



All times are GMT -4. The time now is 12:36 AM.


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