Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > How do you bind a 'Many to Many' data relation to a list box?
 

How do you bind a 'Many to Many' data relation to a list box?

Hi People, 

I have a table of 'Organisations' and a table of 'Contacts'. As a conact can work for more than one organisation I have created a link table called (unsuprisingly) 'OrganisationContacts'. This table just has as it's fields the two primary keys of the other tables. 

I have loaded the values into a datset and have created the data relations between the tables but I now want to bind the list of contacts working for a particular organisation to a list box. I can do it to a textbox (thanks to jfuentes from this forum) but as yet not a list box. 

Any ideas?
MigrationUser 1  Saturday, May 07, 2005 5:36 AM
listbox1.datasource = Myds
listbox1.displaymember = "ParentTable.Relationship.ColumnName1"
listbox1.valuemember = "ParentTable.Relationship.ColumnName2"
MigrationUser 1  Saturday, May 07, 2005 10:32 PM
The above works for a one to one relation but not a many to many. If you have 3 tables, table A, B and C. 

A:
AID - Primary Key

B:
AID - Composite primary key
CID - Composite primary key

C:
CID - Primary Key
Name - Text

The following values in the tables
A:
AID = 1

B:
AID = 1
CID = 1

AID = 1
CID = 2

C:
CID = 1
Name = a

CID = 2
Name = b

The code you sugest returns the following give the above situation:
Given AID of 1 result CID = 1
Instead of CID = 1 and CID =2
MigrationUser 1  Monday, May 09, 2005 12:12 PM
Hi,

It's been a long time. Do you still need the answer?

Please let me know and I'll post one possible way to do that.

Regards,

Marcelo
MarceloRos  Monday, March 03, 2008 4:58 PM

You can use google to search for other answers

Custom Search

More Threads

• bind property to selected row from datagridview
• Set Font Size in a DataGridView Cell
• Datagridview master detail case sensitivity issue
• DataGridView + Adding Rows
• Datagridview combobox after update
• DataGrid With XML and DataSet. Framework 1 + VS 2003
• calculations on Keydown, Keyup events of datagrid
• simplest way to filter what goes into a DataGridView
• SQL Count Function
• does bindingsource.filter doesn't provide multiple filter operations