473,778 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4057
Please use databinding.

http://www.alvas.net - Audio tools for C# and VB.Net developers
"Anthony Bollinger" <to***@noemail. noemailÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ
ÓÌÅÄÕÀÝÅÅ: news:%2******** ********@TK2MSF TNGP04.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(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim ds As New DataSet
Dim parent As New DataTable("Pare ntTable")
Dim col As New DataColumn("ID" , GetType(Integer ))
parent.Columns. Add(col)
col = New DataColumn("Tex t", GetType(String) )
parent.Columns. Add(col)

Dim child As New DataTable("Chil dTable")
col = New DataColumn("ID" , GetType(Integer ))
child.Columns.A dd(col)
col = New DataColumn("PID ", GetType(Integer ))
child.Columns.A dd(col)
col = New DataColumn("Tex t", GetType(String) )
child.Columns.A dd(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(p arent)
ds.Tables.Add(c hild)
Dim relation As New DataRelation("p arent_child",
parent.Columns( "ID"), child.Columns(" PID"))
ds.Relations.Ad d(relation)

Dim parentBS As New BindingSource()
parentBS.DataSo urce = ds
parentBS.DataMe mber = "ParentTabl e"

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.DataSou rce = parentBS
childBS.DataMem ber = "parent_chi ld"

Me.comboBox1.Da taSource = parentBS
Me.comboBox1.Di splayMember = "Text"
Me.comboBox1.Va lueMember = "ID"

Me.comboBox2.Da taSource = childBS
Me.comboBox2.Di splayMember = "Text"
Me.comboBox2.Va lueMember = "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******** ********@TK2MSF TNGP04.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
1659
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
7641
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. What is the SQL command to synchronize these tables? I will be initiating this command through a web interface, so I cannot use enterprise manager. Thank you very much!
4
1969
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 combobox for Models. In both comboboxes I use the NotInList event and code to allow users to enter Makes and Models that are not in the database. When the form is open, I want to limit the users to entering new Makes and Models in the comboboxes and not...
0
1942
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 to and the source object is the subform. My subform record source is a query from another table (vacationTbl). FYI: I was filtering on the subform, but removed it and replaced with
8
12106
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 combobox. What is the solution? Thank you in advance.
1
1319
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 OpinatedGeek comboboxes do seem to work for exacrtly what we want to do but only if you use IE! if i try and run them in netscape navigator it falls over with errors on the load/rendering of the actual control itself so is there any 3rd party...
1
379
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 datasource for all three comboboxes but property Datasource works in different way than I want. It looks like it copies all data to items of each combobox. So it takes more memory (3 * items + 1 * datasource) and works slowly. Is this possible to use...
2
11459
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: Fruit 2: Fruit 3:
2
1997
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 external tables: One for Countries that store each Country as a ID (char(2)), and Name (varchar(50)) pair; One for Medical Conditions, using ID (int) and Name (varchar(50)). Also, the BillTo field refers back to the same table that is being...
0
10292
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7471
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5368
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.