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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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…

803 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