C# WinForms: populating datagridview with datasource from two different tables -
when have populate dgv 1 table it's ok, know how (list< entity > coming database datasource). when have table has fk one, don't know how show property of table (and not id, user wont understand). think i've done linq bad (btw i'm new linq, don't know if need it, @ least here). problem solution comes when try selected id dgv.
private void loaddgv() { buildinglogic obuildinglogic; try { obuildinglogic = new buildinglogic(); societylogic osocietylogic = new societylogic(); list<building> listbuildings = obuildinglogic.getall(); list<society> listsocieties = osocietylogic.getall(); this.dgvbuildings.datasource = (from building in listbuildings join society in listsocieties on building.idsociety equals society.id select new { building.id, fullname = building.fullname, shortname = building.shortname, society = society.name, date = building.date, city = building.city, address = building.adress }).tolist(); } catch (exception ex) { messagebox.show(ex.message, this.text, messageboxbuttons.ok, messageboxicon.error); } { obuildinglogic = null; } } private int itemselectedid() { if (this.dgvbuildings.selectedrows.count > 0) { //something this? //this.dgvbuildings.selectedrows[0].databounditem; } else { return 0; } }
return convert.toint32(this.dgvbuildings.selectedrows[0].cells[0].value);
Comments
Post a Comment