Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I bind textboxes to query behind combobox on SelIndexChg event 1

Status
Not open for further replies.

WantsToLearn

Programmer
Feb 15, 2003
147
0
0
US
Hello everyone,

Let's say that I have the following query populating a combobox:
Code:
Select CustomerID, CompanyName, Address, City, State From Customers
I have set the DataSource property to a DataTable from a DataSet and have also set the DisplayMember and ValueMember properties to CompanyName and CustomerID respectively.

If I have associated textboxes txtAddress, txtCity and txtState, can I bind them somehow to the additional columns in my query? If now, how is the best way to update them in the combobox's SelectedIndexChanged event? Thanks in advance!



 
The easiest way to achieve what you want to do is to put some code in your validated event, which will look up the selected customer id in your table, and then simply populate the text boxes accordingly.
Code:
dim row As DataRow() = dt.Select("customerId=" + combo.selectedvalue)
dim r as datarow = row(0)
text1.text=cstr(r("Address"))



Sweep
...if it works dont mess with it
 
Correction....
Code:
dim row As DataRow() = dt.Select("customerId=" + combo.selectedvalue.ToString)
dim r as datarow = row(0)
text1.text=cstr(r("Address"))

Sweep
...if it works dont mess with it
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top