VB Application combobox 2 values

Posted on 2010-11-21
Last Modified: 2012-05-10

I am wondering a good way to assign the displayed text and the ID value to a combobox in a VB application.
This is windows application not a web app.

I know you can do this easily in a web app, but I am having trouble in a windows app.

In the code below you can see I am grabbing the ID and the name. I want to display the Name in the combobox, but use the selected ID in the next SQL Statement not the name.

Imports System.Data.Odbc

Public Class WOSUB

    Public connectionstring As String

    Private Sub WOSUB_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        connectionstring = "DRIVER={SQL Server};SERVER=xxxx;Trusted_connection=yes;DATABASE=xxxx;"

        Dim queryString As String = "SELECT  WO_TYPE,WO_TYPE_ID FROM WO_TYPE"

        Using connection As New OdbcConnection(connectionstring)

            Dim command As New OdbcCommand(queryString, connection)


            Dim reader As OdbcDataReader = command.ExecuteReader()

            'Goes through Multi-Dem array and adds each row to the combobox vendor

            While reader.Read()


            End While

            ' Call Close when done reading.


        End Using

Open in new window

Question by:fixitben
  • 2
LVL 19

Expert Comment

ID: 34185350
i believe you can bind it to a datasource and use the displaymember/valumember attribute.

where you see the displaymember and can pull the value member from a simple for/next loop

Author Comment

ID: 34185355
Yes I know that. But as you can see I am not binding the datasource via the gui.

Is there a way to do this using code?

LVL 17

Accepted Solution

Zhaolai earned 500 total points
ID: 34185432

Author Closing Comment

ID: 34185479
This worked great!!!!!!!

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Close word object 13 38
update textboxes with Streamreader 21 42
Visual Studio .Net 2012 and Crystal Reports 9 48
Need a starter for ETL protocol? 4 42
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
A short article about problems I had with the new location API and permissions in Marshmallow
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

895 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

15 Experts available now in Live!

Get 1:1 Help Now