winforms - How to bind two tables to Datagridview using entity framework C# -
i have 2 tables estate , estatetype. how bind 2 tables 1 data grid? tried doesn't work.
var getallest = (from ee in agencycontext.estate join eet in agencycontext.estatetype on ee.estateid equals eet.estateid select ee).tolist(); datagridview1.datasource = getallest;
instead of string values estatetype, landscape, description gives me numbers
as suggested @tpayne84 i'm added new columns instead of values:
this code used:
var getallest = (from ee in agencycontext.estate join eet in agencycontext.estatetype on ee.estateid equals eet.estateid select ee).tolist(); datagridviewtextboxcolumn estatetype1 = new datagridviewtextboxcolumn(); datagridviewtextboxcolumn landscape1 = new datagridviewtextboxcolumn(); datagridviewtextboxcolumn description1 = new datagridviewtextboxcolumn(); estatetype1.datapropertyname = "estatetype"; landscape1.datapropertyname = "landscape"; description1.datapropertyname = "discription"; datagridview1.columns.add(estatetype1); datagridview1.columns.add(landscape1); datagridview1.columns.add(description1); datagridview1.datasource = getallest;
the problem looks displaying foreign key id of referenced object instead of property on object wish display.
this happens because allowing datagridview generate columns you.
to remedy this, need create columns yourself:
datagridviewtextboxcolumn namecolumn = new datagridviewtextboxcolumn(); // "name" string representation of property on // object want display. namecolumn.datapropertyname = "name";
Comments
Post a Comment