Answered by:
Entity framework and datagridview

Question
-
Hello !
i'm using entity framework , and i have a datagridview bound with entity.table1.
Table1 Table2
ID1 ID2
Name statusname
City statusNumber
ID1
Table1-Table2 : 1-to-1
In datagridview i want to display all the columns of table1 and the column statusnumber from table2.
Datagridview
ID1 Name City StatusNumber
i have created datagridview , only with columns of table1 , but i don't know how to add the column from table2.
Thank You.
Friday, November 25, 2011 12:24 AM
Answers
-
On 11/24/2011 8:33 PM, dcode25 wrote:> i have selected the datasource for datagridview on design>> And all the column from first table are bound to textbox on> datagridview.Now how to bind the column from other table to a textbox on> datagridview ?>Whether a FormLoad or PageLoad, I suggest you set the Datasource atruntime and have all your objects in a collection of objects, whichwould happen if you use the method of doing the query I am talking aboutand binding that way.All you doing in your way is binding at design time and object on theModel, which happens to be a collection of objects from one table.The way I am showing you is to use the Join with a Select New Shape andshape the object with the properties wanted from the two tables with theresult being a collection of the objects with needed properties that canbe bound to the control.datagridview can be set to use the properties of the new object'sproperties.
- Marked as answer by Alan_chen Thursday, December 29, 2011 6:23 AM
Friday, November 25, 2011 2:24 AM
All replies
-
On 11/24/2011 7:24 PM, dcode25 wrote:> Hello !>> i'm using entity framework , and i have a datagridview bound with> entity.table1.>> Table1 Table2>> ID1 ID2>> Name statusname>> City statusNumber>> ID1>> Table1-Table2 : 1-to-1>> In datagridview i want to display all the columns of table1 and the> column statusnumber from table2.>> Datagridview>> ID1 Name City StatusNumber>> i have created datagridview , only with columns of table1 , but i don't> know how to add the column from table2.>> Thank You.>Do a join on the two table and do a 'new' Select New Shape. The resultswill be an output of table1 and table2 properties.var q = from c in customersjoin o in orders on c.Key equals o.Keyselect new {c.Name, o.OrderNumber};Friday, November 25, 2011 1:10 AM
-
-
i have selected the datasource for datagridview on design
And all the column from first table are bound to textbox on datagridview.Now how to bind the column from other table to a textbox on datagridview ?
Friday, November 25, 2011 1:33 AM -
On 11/24/2011 8:33 PM, dcode25 wrote:> i have selected the datasource for datagridview on design>> And all the column from first table are bound to textbox on> datagridview.Now how to bind the column from other table to a textbox on> datagridview ?>Whether a FormLoad or PageLoad, I suggest you set the Datasource atruntime and have all your objects in a collection of objects, whichwould happen if you use the method of doing the query I am talking aboutand binding that way.All you doing in your way is binding at design time and object on theModel, which happens to be a collection of objects from one table.The way I am showing you is to use the Join with a Select New Shape andshape the object with the properties wanted from the two tables with theresult being a collection of the objects with needed properties that canbe bound to the control.datagridview can be set to use the properties of the new object'sproperties.
- Marked as answer by Alan_chen Thursday, December 29, 2011 6:23 AM
Friday, November 25, 2011 2:24 AM