473,387 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ComboBox select Values How?

Im populating a combobox from query results like that
below. This works great for populating the box, but I dont
want the selected text, but the ID info associated with
the selection. The query returns Name,ID. I only want to
display the Name in the box, but pull the ID value as the
selected value. I could do this with web forms in .net,
but not with Windows forms controls. Any help would be
great.
EXAMPLE:
Dim dreader As SqlClient.SqlDataReader
DTE.Open()
dreader = SelectExpense.ExecuteReader()
While dreader.Read()
CBO_EType.Items.Add(dreader(0).ToString())
End While
..
Nov 20 '05 #1
3 14695
Eric,

Use the DisplayMember and ValueMember properties of the ComboBox. Code
example follows:
Private loading As Boolean

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim cn As New SqlConnection("Server=(local);Database=Pubs;Integr ated
Security=SSPI")
Dim da As New SqlDataAdapter("SELECT au_lname, au_id FROM Authors",
cn)
Dim dt As New DataTable

loading = True
da.Fill(dt)
ComboBox1.DataSource = dt
ComboBox1.DisplayMember = "au_lname"
ComboBox1.ValueMember = "au_id"
loading = False
End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged
If Not loading Then
MsgBox(ComboBox1.SelectedValue.ToString)
End If
End Sub
"Eric" <er*************@kutakrock.com> wrote in message
news:01****************************@phx.gbl...
Im populating a combobox from query results like that
below. This works great for populating the box, but I dont
want the selected text, but the ID info associated with
the selection. The query returns Name,ID. I only want to
display the Name in the box, but pull the ID value as the
selected value. I could do this with web forms in .net,
but not with Windows forms controls. Any help would be
great.
EXAMPLE:
Dim dreader As SqlClient.SqlDataReader
DTE.Open()
dreader = SelectExpense.ExecuteReader()
While dreader.Read()
CBO_EType.Items.Add(dreader(0).ToString())
End While
.

Nov 20 '05 #2
Eric,

Use the DisplayMember and ValueMember properties of the ComboBox. Code
example follows:

--
Rob Windsor
G6 Consulting
Toronto, Canada

Private loading As Boolean

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim cn As New SqlConnection("Server=(local);Database=Pubs;Integr ated
Security=SSPI")
Dim da As New SqlDataAdapter("SELECT au_lname, au_id FROM Authors",
cn)
Dim dt As New DataTable

loading = True
da.Fill(dt)
ComboBox1.DataSource = dt
ComboBox1.DisplayMember = "au_lname"
ComboBox1.ValueMember = "au_id"
loading = False
End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged
If Not loading Then
MsgBox(ComboBox1.SelectedValue.ToString)
End If
End Sub
"Eric" <er*************@kutakrock.com> wrote in message
news:01****************************@phx.gbl...
Im populating a combobox from query results like that
below. This works great for populating the box, but I dont
want the selected text, but the ID info associated with
the selection. The query returns Name,ID. I only want to
display the Name in the box, but pull the ID value as the
selected value. I could do this with web forms in .net,
but not with Windows forms controls. Any help would be
great.
EXAMPLE:
Dim dreader As SqlClient.SqlDataReader
DTE.Open()
dreader = SelectExpense.ExecuteReader()
While dreader.Read()
CBO_EType.Items.Add(dreader(0).ToString())
End While
.

Nov 20 '05 #3
Thanks Rob, It seems like a ton of overhead; populating a
dataset then binding to it, but whatever works.
much thanks, Eric
-----Original Message-----
Eric,

Use the DisplayMember and ValueMember properties of the ComboBox. Codeexample follows:

--
Rob Windsor
G6 Consulting
Toronto, Canada

Private loading As Boolean

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles MyBase.Load
Dim cn As New SqlConnection("Server= (local);Database=Pubs;IntegratedSecurity=SSPI")
Dim da As New SqlDataAdapter("SELECT au_lname, au_id FROM Authors",cn)
Dim dt As New DataTable

loading = True
da.Fill(dt)
ComboBox1.DataSource = dt
ComboBox1.DisplayMember = "au_lname"
ComboBox1.ValueMember = "au_id"
loading = False
End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender AsSystem.Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged
If Not loading Then
MsgBox(ComboBox1.SelectedValue.ToString)
End If
End Sub
"Eric" <er*************@kutakrock.com> wrote in message
news:01****************************@phx.gbl...
Im populating a combobox from query results like that
below. This works great for populating the box, but I dont want the selected text, but the ID info associated with
the selection. The query returns Name,ID. I only want to
display the Name in the box, but pull the ID value as the selected value. I could do this with web forms in .net,
but not with Windows forms controls. Any help would be
great.
EXAMPLE:
Dim dreader As SqlClient.SqlDataReader
DTE.Open()
dreader = SelectExpense.ExecuteReader()
While dreader.Read()
CBO_EType.Items.Add(dreader(0).ToString())
End While
.

.

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Keith | last post by:
Hello - this started out as a minor annoyance - and now is starting to bother me more and more - I'm hoping someone can help me. I would like to have a combobox display - NOT initially be blank...
5
by: James P. | last post by:
Hello, For my new Windows application, all I want is to create an initial form to demo to the user to show them how it looks like with some data on it. So I figure the fastest way is to create...
4
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box...
2
by: shumaker | last post by:
I have a combobox that is very much like the one found in the RSS project here: http://msdn.microsoft.com/vstudio/express/visualCSharp/learning/ My projectNameComboBox basically is filled with a...
10
by: ZaphodBBB | last post by:
HI I have a form with 2 comboBoxes. The first comboBox gives me a list of customers to select from. I would like to have the second comboBox populated with the names of Departments. I only want...
0
by: nedier26 | last post by:
Hi everyone, I have a control array that contains two ComboBox and I used a Select Case to make the difference between the ComboBox and I also diferentiate the two ComboBox using their Index...
1
by: The.Daryl.Lu | last post by:
Hi, two parts to my problem if someone can help address either one or both: 1. I want to SELECT everything in the table if it matches the criteria when the query button is pressed (this is just...
19
by: billa856 | last post by:
Hi, I have to use the table(PRODUCTION) already generated in MS Access in which all fields are of TEXT type.fields like (orderdate,palletno,customercode,itemno,pono,carto n,pcs,totalquantity)Now i...
1
by: BASSPU03 | last post by:
I've set my combobox to operate according to this option: "Find a record on my form based on a value I selected from my combobox." When I select a value from the combobox, I can see that the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.