?
Solved

Difficulty Binding a Combobox to a Database

Posted on 2005-02-28
4
Medium Priority
?
184 Views
Last Modified: 2010-04-23
I am writing a windows form app.  I want to bind a combobox to a dataset.  I want the combobox to display the Name and I also want an ID value that is associated with the Name.  

cbx.datasource=dt
cbx.displaymember="Name"
cbx.valuemember="ID"

The items appear in the combobox fine but when I try to display the value I get nothing.  What am I doing wrong?

msgbox(cstr(cbx.selectedvalue))

Thanks.
0
Comment
Question by:pamwestphal
[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
  • 2
  • 2
4 Comments
 
LVL 34

Accepted Solution

by:
Brian Crowe earned 150 total points
ID: 13423253
msgbox(dt.rows(cbx.selectedindex).item("ID").tostring)
0
 

Author Comment

by:pamwestphal
ID: 13423395
That works but shouldn't I be able to bind the ID value by using the cbx.valuemember then read the selectedvalue to get the value corrosponding to the selected value?  The way you have here I shouldn't even need to bind the valuemember to anything.
0
 
LVL 34

Expert Comment

by:Brian Crowe
ID: 13423435
the selected value is a datarow so you could probably use

msgbox(ctype(cbx.selectedvalue), datarow).item("ID").tostring)

but that's not any better

You're correct the valuemember isn't of much use in this case.  It's meant more for manually defined combobox'es
0
 

Author Comment

by:pamwestphal
ID: 13423461
OK Thanks.
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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

762 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