Click here to Skip to main content
Sign Up to vote bad
good
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 11 Feb '10 - 10:38
peterchen142K
Edited 13 Feb '10 - 3:54


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.
 
Wink | ;)
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 419
1 Mahesh Bailwal 303
2 CPallini 245
3 Maciej Los 240
4 Aarti Meswania 173
0 Sergey Alexandrovich Kryukov 9,162
1 OriginalGriff 7,179
2 CPallini 3,913
3 Rohan Leuva 3,176
4 Maciej Los 2,588


Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 13 Feb 2010
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid