Question Populate a textbox.value based on Combobox selection

zendog1960

Member
Joined
Jan 9, 2008
Messages
19
Programming Experience
Beginner
I am using VS 2008 VB.net Framework 3.5 creating a winform application.

I have one form (Form1), 1 combobox (ComboBox1), and 1 textbox (TextBox1)
I have two tables (Players, Teams) in my local database which was created within the project.
In Table 'Teams' I only have two columns (TeamID - Primary Key, TeamName)
In Table 'Players' I have three columns (PlayerID - Primary Key, FName, LName)
Each table has two records in it.

I have one data set (TestDataSet) that includes all the columns from the two above mentioned tables.

What I need to find out is how do have get the textbox to populate with the corresponding team for whatever player is selected in the combobox. Any and all help would be appreciated.

Zen
 
Tricky, seeing as logic dictates that the team is the parent and the player is the child. I'd turn the datarelation around in the dataset so that team was a child of player then:

Show data sources window
Expand TestDataSet
Expand Player
Change Playername entry to combobox
Drag playername entry to form (combo appears)
Unbind the .text property (if bound) and ensure the datasource, value and displaymembers are set to sensible values, and set the combo to dropdownlist - this turns the combo into something that navigates, rather than edits
In the datasources window again, thre are 2 Teams entries, one underneath players - expand this one
Drag the team name to the form

Now you have: Player name combo, team name textbox, 2 bindingsource, the team bindingsource has its datasource set to the relation exposed by the player binding source

Ensure the code behind contains commands to fill both the teams and the players (players first)


When you nav the player, the team name will alter
 
Back
Top