title: C# WinForms: populating datagridview with datasource from two different tables
body: <p>When I have to populate a dgv with only 1 table it's ok, I know how to do it (List&lt; Entity > coming from database to datasource). But when I have a table that has a FK with another one, I don't know how to show another property of that table (and not the ID, that the user wont understand). I think what I've done with LINQ is really bad (BTW I'm new to LINQ, I don't know if I need it, at least here). The problem with my solution comes when I try to get the selected ID from the DGV.</p>
  
  <pre><code>private void LoadDGV()
      {
          BuildingLogic oBuildingLogic;
          try
          {
              oBuildingLogic = new BuildingLogic();
              SocietyLogic oSocietyLogic = new SocietyLogic();
              List&lt;Building&gt; listBuildings = oBuildingLogic.GetAll();
              List&lt;Society&gt; 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);
          }
          finally
          {
              oBuildingLogic = null;
          }
      }
  
      private int ItemSelectedID()
      {
          if (this.dgvBuildings.SelectedRows.Count &gt; 0)
          {
              //something like this?
              //this.dgvBuildings.SelectedRows[0].DataBoundItem;
          }
          else
          {
              return 0;
          }
      }
  </code></pre>