Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Difficulty Binding a Combobox to a Database

Posted on 2005-02-28
4
Medium Priority
?
185 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
  • 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Integration Management Part 2
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

578 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