Binding data to a Combo Box

G

Guest

Help me. I am obviously stupid! :)
I am just starting out with VB.Net and am trying to do a simple master/detail form with a SqlServer backend.
I have created a combo box which is to populate with 'STATUS_DESC' from the STATUS table.
This works perfectly.
Now I want to populate the form with a row from the Purchase Order table
POHEADER and expect the combo box to get the 'STATUS_DESC' by looking up the STATUS table with POHEADER.STATUS_ID.
How come when I fill the dataset, the combo box gets the STATUS_ID instead?

I have the following values in the combo box properties:
DataSource: DsPurchaseOrder1.STATUS
DisplayMember: STATUS_DESC
ValueMember: STATUS_ID

In my book it talks about the 'SelectedValue' property but I can't seem to find that anywhere in the properties dialog.
Please help! How do i get it to lookup the description once it's retrieved the STATUS_ID from the Dataset?


THANKS!!
 
O

One Handed Man \( OHM - Terry Burns \)

What do you mean when you say the Combo box 'Gets' the STATUS_ID, do you
mean that is what is displayed ?

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

SoftWhiteDelgiht said:
Help me. I am obviously stupid! :)
I am just starting out with VB.Net and am trying to do a simple
master/detail form with a SqlServer backend.
I have created a combo box which is to populate with 'STATUS_DESC' from the STATUS table.
This works perfectly.
Now I want to populate the form with a row from the Purchase Order table
POHEADER and expect the combo box to get the 'STATUS_DESC' by looking up
the STATUS table with POHEADER.STATUS_ID.
How come when I fill the dataset, the combo box gets the STATUS_ID instead?

I have the following values in the combo box properties:
DataSource: DsPurchaseOrder1.STATUS
DisplayMember: STATUS_DESC
ValueMember: STATUS_ID

In my book it talks about the 'SelectedValue' property but I can't seem to
find that anywhere in the properties dialog.
Please help! How do i get it to lookup the description once it's retrieved
the STATUS_ID from the Dataset?
 
G

Guest

Hi Terry,
Yes, it displays the id instead of the description.
ie. When the screen first displays it populates the combo box with all the statuses. 'Approved', 'Closed' etc.
When I enter a Purchase Order number and fill the dataset, the Combo Box displays the number 5 and it is no longer populated with the statuses.
Here is the code:

Me.ComboBox1.DataBindings.Add(New System.Windows.Forms.Binding("Tag", Me.DsPurchaseOrder1, "POHEADER.PO_PONO"))
Me.ComboBox1.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.DsPurchaseOrder1, "POHEADER.PO_STATUS"))
Me.ComboBox1.DataBindings.Add(New System.Windows.Forms.Binding("SelectedValue", Me.DsPurchaseOrder1, "POHEADER.PO_STATUS"))
Me.ComboBox1.DataSource = Me.DsPurchaseOrder1.STATUS
Me.ComboBox1.DisplayMember = "STATUS_DESC"
Me.ComboBox1.Location = New System.Drawing.Point(464, 121)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(120, 21)
Me.ComboBox1.TabIndex = 63
Me.ComboBox1.Tag = ""
Me.ComboBox1.ValueMember = "STATUS_ID"

Thanks for your help.
Regards,
Marnie.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top