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
Solved

VB Application combobox 2 values

Posted on 2010-11-21
4
260 Views
Last Modified: 2012-05-10
Hi,

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.

Thanks
Fixitben
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)
            connection.Open()

            Dim reader As OdbcDataReader = command.ExecuteReader()
            'Goes through Multi-Dem array and adds each row to the combobox vendor
            While reader.Read()
                WOTYPEComboBox1.Items.Add(RTrim(reader(0).ToString))
            End While

            ' Call Close when done reading.
            reader.Close()

        End Using

Open in new window

0
Comment
Question by:fixitben
  • 2
4 Comments
 
LVL 19

Expert Comment

by:weellio
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
0
 
LVL 7

Author Comment

by:fixitben
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?

Thanks
Fixitben
0
 
LVL 17

Accepted Solution

by:
Zhaolai earned 500 total points
ID: 34185432
0
 
LVL 7

Author Closing Comment

by:fixitben
ID: 34185479
This worked great!!!!!!!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
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…

860 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