Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have a database containing two tables, Products and ProductLicences. ProductLicences.ProductID has a foreign key refereince to Products.ProductID.

How do I represent that relationship in a WinForms DataGridView?

When feeding the DtaaGridView (SQL Metal and through LINQ to SQL), the ProductLicences.ProductID, it automatically generates a column with a text field expecting a "Product" (which of course I can't enter...).

How do I change this column to contain a combobox listing the available products?
Posted
Updated 13-Feb-10 3:54am
v3

1 solution

I think if you create the relationship within the dataset, and put the dataset to the DataGrid's DataSource, it will automatically show you the relationship in the view.

DataRelation drelation = new DataRelation("RelationName", ds.Tables[0].Columns["Col1"], ds.Tables[1].Columns["Col2"]);

Now
ds.Relations.Add(drelation);


This will add a new datarelation between the Table0 and Table1 within the DataSet ds.

;)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900