473,327 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Synchronize Two Comboboxes

I have two tables in a master-detail relationship. When I make a selection
in one combobox, how do I have it display the values from a second combobox?
Each table has a key and a text value for each record. I don't yet see the
way to update the list of values in the second combobox.

Thanks for any input,
Tony
Nov 15 '07 #1
5 4035
Please use databinding.

http://www.alvas.net - Audio tools for C# and VB.Net developers
"Anthony Bollinger" <to***@noemail.noemailÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ
ÓÌÅÄÕÀÝÅÅ: news:%2****************@TK2MSFTNGP04.phx.gbl...
>I have two tables in a master-detail relationship. When I make a selection
in one combobox, how do I have it display the values from a second
combobox? Each table has a key and a text value for each record. I don't
yet see the way to update the list of values in the second combobox.

Thanks for any input,
Tony

Nov 16 '07 #2
Hi Tony,

Based on my understanding, you have two DataTables in a master-detail
relationship and two ComboBoxes. What you want is to have one ComboBox show
the data in the master table and the other ComboBox show the corresponding
records in the detail table. If I'm off base, please feel free to let me
know.

If you're using VS05, you can add a DataRelation between the master and
detail tables and use BindingSource as the data source of the ComboBoxes.

I will illustrate this with an example. Create a WinForm application
project and add two ComboBoxes on the form. In the Form Load event hanlder,
add the following code:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim ds As New DataSet
Dim parent As New DataTable("ParentTable")
Dim col As New DataColumn("ID", GetType(Integer))
parent.Columns.Add(col)
col = New DataColumn("Text", GetType(String))
parent.Columns.Add(col)

Dim child As New DataTable("ChildTable")
col = New DataColumn("ID", GetType(Integer))
child.Columns.Add(col)
col = New DataColumn("PID", GetType(Integer))
child.Columns.Add(col)
col = New DataColumn("Text", GetType(String))
child.Columns.Add(col)

Dim row As DataRow = parent.NewRow
row(0) = 1
row(1) = "parent text 1"
parent.Rows.Add(row)

row = parent.NewRow
row(0) = 2
row(1) = "parent text 2"
parent.Rows.Add(row)

row = parent.NewRow
row(0) = 3
row(1) = "parent text 3"
parent.Rows.Add(row)

row = child.NewRow()
row(0) = 1
row(1) = 1
row(2) = "child text 1"
child.Rows.Add(row)

row = child.NewRow()
row(0) = 2
row(1) = 1
row(2) = "child text 2"
child.Rows.Add(row)

row = child.NewRow()
row(0) = 3
row(1) = 2
row(2) = "child text 3"
child.Rows.Add(row)

row = child.NewRow()
row(0) = 4
row(1) = 2
row(2) = "child text 4"
child.Rows.Add(row)

row = child.NewRow()
row(0) = 5
row(1) = 3
row(2) = "child text 5"
child.Rows.Add(row)

row = child.NewRow()
row(0) = 6
row(1) = 3
row(2) = "child text 6"
child.Rows.Add(row)

ds.Tables.Add(parent)
ds.Tables.Add(child)
Dim relation As New DataRelation("parent_child",
parent.Columns("ID"), child.Columns("PID"))
ds.Relations.Add(relation)

Dim parentBS As New BindingSource()
parentBS.DataSource = ds
parentBS.DataMember = "ParentTable"

Dim childBS As New BindingSource
' Set the DataSource property of the childBS to the parentBS and
the DataMember property to the data relation. This is the key point.
childBS.DataSource = parentBS
childBS.DataMember = "parent_child"

Me.comboBox1.DataSource = parentBS
Me.comboBox1.DisplayMember = "Text"
Me.comboBox1.ValueMember = "ID"

Me.comboBox2.DataSource = childBS
Me.comboBox2.DisplayMember = "Text"
Me.comboBox2.ValueMember = "ID"

End Sub

Build the project and run the application. You should see the text
displayed in the comboBox1 is "parent text 1" and its drop down list
contains three items "parent text 1", "parent text 2" and "parent text 3".
The drop down list of the comBox2 contains two items "child text 1" and
"child text 2". If you select "parent text 2" in the comboBox1, the drop
down list of the comboBox2 contains "child text 3" and "child text 4".

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 16 '07 #3
See
http://www.emoreau.com/Entries/Artic...-ComboBox.aspx

--
HTH

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc. (http://www.emoreau.com)
Membre du réseau .NET Expertise www.dotnet-expertise.com
"Anthony Bollinger" <to***@noemail.noemailwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>I have two tables in a master-detail relationship. When I make a selection
in one combobox, how do I have it display the values from a second
combobox? Each table has a key and a text value for each record. I don't
yet see the way to update the list of values in the second combobox.

Thanks for any input,
Tony

Nov 16 '07 #4
Thanks Linda and Eric. I am attempting it with an Access DB, so I will give
your suggestions a whirl. Great input. --Tony
Nov 16 '07 #5
Hi Tony,

I am reviewing this post and would like to know the status of this issue.

If you have any question, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support

Nov 20 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Thomas Rademacher | last post by:
Hallo, I want to synchronize the main function of my script. I havn't a class structure in my script. def main(): # my code to synchronized if __name__=='__main__': main()
4
by: gene.ellis | last post by:
Using a web interface, I am placing text into a SQL database. From time to time, I would like to synchronize one of my other tables in the database with the table that I am inserting content into....
4
by: Kathy | last post by:
In my custom menu one menu item opens a form to add new Makes to TblMakes and another menu item opens a form to add new Models to TblModels. I have a form that has a combobox for Makes and a...
0
by: johnson_cy | last post by:
I am using Access 2000. My main form has a record source of a table (employeeTbl with key of . It is filtering the record results. My subform and mainform have the link child/link master set...
8
by: Zlatko Matiæ | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
1
by: Craig G | last post by:
for months we have been dabling round looking at various 3rd party comboboxes that allow the user to type text into the combobox as a search mechanism what we've found is that the likes of...
1
by: Marcin Podle¶ny | last post by:
Hi, I've a form with three comboboxes. Each of them contains the same data - all cities in my country. As you see it's a lot of data so it takes a lot of memory. I'd like to use the same...
2
by: Matt | last post by:
Hi all, me again! :) I've now got an issue with combo boxes. Basically, I have a number of items that I want a user to pick from a single list. It's basically along the lines of: Fruit 1: ...
2
by: Wingot | last post by:
Hey, I have a view to a database that I have created for Client Maintenance. It has a number of fields, but the important ones are Medical Condition, Bill To, and Country. I have a couple of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.