Solved

VB Application combobox 2 values

Posted on 2010-11-21
4
256 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
Comment Utility
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
Comment Utility
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
Comment Utility
0
 
LVL 7

Author Closing Comment

by:fixitben
Comment Utility
This worked great!!!!!!!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
A short article about problems I had with the new location API and permissions in Marshmallow
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

772 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

11 Experts available now in Live!

Get 1:1 Help Now