J
Joe Schmoe
All I want to to be able to take a two-column DataReader (One column with
the Item ID number, the other with Item Description text) and load it into a
Windows Forms ComboBox (Set to DropDownList mode) so that I the dropdown
shows the Item Descriptions, but returns the Item ID number when selected.
Completely easy in ASP.NET, but I cannot figure out how to do the same in a
Windows Forms app. Obviously the Windows Forms ComboBox is a lot more
feature-filled, but all I want is a single-row item picker.
Code that does exactly what I want in ASP.NET follows. Please help me
translate it to what I need to do the same thing in a Windows Forms app.
Thanks!
Sub LoadRetailerGroups()
' Not using a sproc simply because this app is only a one-shot utility
to load data once
Dim dbQuery As String = "SELECT Distinct RetailerGroupID, RetailerGroup
FROM tbl_RetailerGroup ORDER BY RetailerGroup`"
Dim dbCmd As New System.Data.SqlClient.SqlCommand(dbQuery, dbCon)
dbCon.Open()
Dim dbReader As SqlDataReader
dbReader = dbCmd.ExecuteReader()
ddlRetailerGroup.DataSource = dbReader
ddlRetailerGroup.DataTextField = "RetailerGroup"
ddlRetailerGroup.DataValueField = "RetailerGroupID"
ddlRetailerGroup.DataBind()
dbReader.Close()
dbCon.Close()
End Sub
Thanks!
the Item ID number, the other with Item Description text) and load it into a
Windows Forms ComboBox (Set to DropDownList mode) so that I the dropdown
shows the Item Descriptions, but returns the Item ID number when selected.
Completely easy in ASP.NET, but I cannot figure out how to do the same in a
Windows Forms app. Obviously the Windows Forms ComboBox is a lot more
feature-filled, but all I want is a single-row item picker.
Code that does exactly what I want in ASP.NET follows. Please help me
translate it to what I need to do the same thing in a Windows Forms app.
Thanks!
Sub LoadRetailerGroups()
' Not using a sproc simply because this app is only a one-shot utility
to load data once
Dim dbQuery As String = "SELECT Distinct RetailerGroupID, RetailerGroup
FROM tbl_RetailerGroup ORDER BY RetailerGroup`"
Dim dbCmd As New System.Data.SqlClient.SqlCommand(dbQuery, dbCon)
dbCon.Open()
Dim dbReader As SqlDataReader
dbReader = dbCmd.ExecuteReader()
ddlRetailerGroup.DataSource = dbReader
ddlRetailerGroup.DataTextField = "RetailerGroup"
ddlRetailerGroup.DataValueField = "RetailerGroupID"
ddlRetailerGroup.DataBind()
dbReader.Close()
dbCon.Close()
End Sub
Thanks!