PC Review


Reply
Thread Tools Rate Thread

ComboBox select Values How?

 
 
Eric
Guest
Posts: n/a
 
      2nd Sep 2003
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
..


 
Reply With Quote
 
 
 
 
Rob Windsor
Guest
Posts: n/a
 
      2nd Sep 2003
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;Integrated
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" <(E-Mail Removed)> wrote in message
news:01da01c3716e$51637680$(E-Mail Removed)...
> 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
> .
>
>



 
Reply With Quote
 
Rob Windsor
Guest
Posts: n/a
 
      2nd Sep 2003
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;Integrated
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" <(E-Mail Removed)> wrote in message
news:01da01c3716e$51637680$(E-Mail Removed)...
> 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
> .
>
>



 
Reply With Quote
 
Eric
Guest
Posts: n/a
 
      2nd Sep 2003
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. 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;Integrated
>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" <(E-Mail Removed)> wrote in message
>news:01da01c3716e$51637680$(E-Mail Removed)...
>> 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
>> .
>>
>>

>
>
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Howto make Combobox requery based on dependant combobox values Shane Microsoft Access Form Coding 1 22nd Apr 2008 09:14 AM
when i select a value in one combobox - all CB values change to sa =?Utf-8?B?bHBqZW5uaWZlcg==?= Microsoft Access Forms 1 6th Dec 2004 05:54 AM
1 form with 2 ComboBoxes pointing to the same source table. How to select diff. values in each ComboBox? =?Utf-8?B?QUc=?= Microsoft Access Forms 11 1st Apr 2004 01:41 AM
Values contained in value list of second combobox based on value selected in first combobox. Anthony Microsoft Access Forms 16 6th Mar 2004 04:07 AM
combobox: how can allow select multiple values in a field andrea Microsoft Access Forms 2 16th Oct 2003 09:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:49 AM.