Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: LINQ database DataGridView , +
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 11:38am
peterchen148.1K
Edited 13-Feb-10 4:54am
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
0 OriginalGriff 587
1 Sergey Alexandrovich Kryukov 519
2 Maciej Los 305
3 BillWoodruff 250
4 Mathew Soji 195
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,777
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100