Click here to Skip to main content
12,823,954 members (46,398 online)
Rate this:
 
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
peterchen154K
Updated 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.

;)
  Permalink  

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

    Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 13 Feb 2010
Copyright © CodeProject, 1999-2017
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