[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

VB Application combobox 2 values

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
fixitben
Asked:
fixitben
  • 2
1 Solution
 
William ElliottSr Tech GuruCommented:
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
 
fixitbenAuthor Commented:
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
 
ZhaolaiCommented:
0
 
fixitbenAuthor Commented:
This worked great!!!!!!!
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now