populate form from selected combobox record
-
Friday, January 06, 2006 6:13 PMi'm sure it is easy, but I cannot get text boxes to be populated from a selected record from a combo box. I can make a combo box and get it to pull up records from the Access table, and can even get it to populate a data grid. What i want to do is pick Fred's name from the customer table in the combox box (or which ever on is selected) and to get other fields of that record to populate textboxes on the form as: address, city.... i don't want to populate a listbox or datagrid with the selected rec...can you point me in the right direction to accomplish this task? ....thanks in advance.
All Replies
-
Friday, January 06, 2006 11:37 PM
If you double click on the combobox then a Private Sub will be added to the code space. The default Sub will be called something like "Private Sub ComboBox_SelectedIndexChanged" and it will run whenever a user changes the index of the combobox.
From here I know of two different ways to populate other fields. The first is to do a series of IF statements and the second is to use a Select Case statement. Here are a few examples:
Private Sub ComboBox_SelectedIndexChange(...a lot of stuff ...) - IF Method
If (ComboBox.Text = "Fred") Then
AddressBox.Text = Access Database Location
CityBox.Text = Access database Location
End If
If (ComboBox.Text = "Wilma") Then
AddressBox.Text = Access Database Location
CityBox.Text = Access database Location
End If
End Sub
Private Sub ComboBox_SelectedIndexChange(...a lot of stuff...) - Select Case Method
Select Case (ComboBox.Text)
Case ("Fred")
AddressBox.Text = Access Database Location
CityBox.Text = Access database Location
Case ("Shaggy")
AddressBox.Text = Access Database Location
CityBox.Text = Access database Location
End Select
End Sub
Hope this helps!
-
Saturday, January 07, 2006 12:15 AM
Hello
You can do this with the new built in RAD support in whidbey . Using the Add new Datasource wizard , create a dataset with the table you need to use. Show the datasource window . Say if you are using Customers table from Northwind database .Change CustomerId to a combo box . Set the menu option to details .Drag and drop Customers from datasource window on to winform designer .
To get what you wanted , you just have change bindings on combo box . Click on the combo box and set the Datasource = CustomersBindingSource Display member and Value member to CustomerID . Delete the bindings from Databinding.Text . Press F5 and app is ready to go
For more info on the new features take a look
http://msdn2.microsoft.com/en-us/library/fxsa23t6.aspx
Hope this helps
Sunder
Vb.net
-
Saturday, January 07, 2006 2:18 PMThat was EXACTLY what I was looking for. Thank you. I another is having the same problem, sunder's link is great. The document thaqt you'd want is Displaying Data on a form in a Windows Application.

