472,093 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Lookup Field Values Based on Combobox Change

Hi,
I'm trying to populate textbox values upon a change in a combobox
selection. I'm using the Publishers table in the Pubs sample database
as a simplified example. Here is the code:

Private Sub cboPubID_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
cboPubID.SelectedIndexChanged
Dim PubsDS As New PUBSDataSet()
Dim PubsTA As New
PUBSDataSetTableAdapters.publishersTableAdapter

PubsTA.Fill(PubsDS.publishers)

txtPubName.Text =
PubsDS.Tables("publishers").Rows(cboPubID.Text)(1) .ToString
txtCity.Text = PubsDS.Tables("publishers").Rows(cboPubID.Text)
(2).ToString
End Sub
The last two lines are where I am trying to lookup the field values in
columns 1 and 2 based on the row as determined from the combobox
selection. These lines aren't working. I've tried searching this
board for the answer, but no luck.

Anybody know how to do this?
Thanks,
Randy

Apr 6 '07 #1
2 1697
Here's another attempt, but it comes back empty. Why?

txtCity.Text =
PubsDS.Tables("publishers").Rows(cboPubID.Selected Index).Item(1).ToString

Please help. I'm stuck!!! Robin, my savior? Cor (I do like you, you
know)? ;^)

Randy

Apr 7 '07 #2
If you load your table and bind your combobox using my code in my response
to your other post, each entry in the combobox is a datarow, and you should
be able to pull the data like this:

Dim drv As DataRowView = CType(TableComboBox.SelectedItem, DataRowView)
Debug.Print("First Column = {0}, Second column = {1}", _
CType(drv("PubID"), Integer), drv("PublisherName").ToString)

Each item in the combobox is a datarow.

If you bind your combobox to a List(Of T), each item will be an instance of
T.

Good luck.
Robin S.
-----------------------
"Randy" <sp***********@gmail.comwrote in message
news:11**********************@y66g2000hsf.googlegr oups.com...
Here's another attempt, but it comes back empty. Why?

txtCity.Text =
PubsDS.Tables("publishers").Rows(cboPubID.Selected Index).Item(1).ToString

Please help. I'm stuck!!! Robin, my savior? Cor (I do like you, you
know)? ;^)

Randy

Apr 7 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by my-wings | last post: by
reply views Thread by leo001 | last post: by

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.