title: Populating datagridview winforms .net 4.0
body: <p>I am having problems in loading a datagridview with 2 columns.
  Form with a Datagridview and 1 button.</p>
  
  <p>Department (text)
  EmployeesByDpt( Combo)</p>
  
  <p>I have a form with a datagridview and a Button (Load),when I press load the datagridview should be populated.
  clicking on the Employee Combo should display all the employees that belong to a particular department.</p>
  
  <p>I cannot seem to get it to work ,below is what I have done,</p>
  
  <p>Any suggestions?At the moment nothing shows.<strong>Thanks</strong></p>
  
  <p>Code (for semplicity I have put all together)</p>
  
  <pre><code>     public partial class Form2 : Form
  {
      Repository repository;
      readonly DataGridViewTextBoxColumn colDepartment=new DataGridViewTextBoxColumn();
      readonly DataGridViewComboBoxColumn colComboEmployeesByDpt = new DataGridViewComboBoxColumn();
      public Form2()
      {
          InitializeComponent();
          repository = new Repository();
          SetupDataGridView();
      }
  
      private void SetupDataGridView()
      {
          dataGridView1.EditingControlShowing += OnEditingControlShowing;
          dataGridView1.CellValueChanged += OnCellsValueChanged;
          dataGridView1.AutoGenerateColumns = false;
  
          colDepartment.DataPropertyName = "Name";
          colDepartment.HeaderText = "Department Name";
  
          colComboEmployeesByDpt.DataPropertyName = "Employees";
          colComboEmployeesByDpt.HeaderText = "Employees";
          colComboEmployeesByDpt.DisplayMember = "FullName";
          //colComboEmployeesByDpt.DataSource = "FullName";
  
  
          dataGridView1.Columns.AddRange(new DataGridViewColumn[] { colDepartment ,colComboEmployeesByDpt});
      }
  
      private void OnCellsValueChanged(object sender, DataGridViewCellEventArgs e)
      {
  
      }
  
      private void OnEditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
      {
          if (dataGridView1.CurrentCell.ColumnIndex == colDepartment.Index)
          {
              var control = e.Control as DataGridViewComboBoxEditingControl;
              if (control != null)
              {
                  var bs = control.DataSource as BindingSource;
                  if (bs != null)
                  {
                      var comboBox = e.Control as ComboBox;
                      BindingList&lt;Employee&gt; employees = repository.GetEmployeeByDepartments(control.Text);
                      comboBox.DataSource = employees;
                      object employeeValue = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[colComboEmployeesByDpt.Index].Value;
                      if (employeeValue == DBNull.Value || employeeValue == null)
  
                      if (dataGridView1.CurrentCell.Value != DBNull.Value &amp;&amp; dataGridView1.CurrentCell.Value != null)
                      {
                          control.SelectedValue = dataGridView1.CurrentCell.Value;
                      }
                  }
              }
          }
      }
  
      private void btnLoad_Click(object sender, EventArgs e)
      {
  
          BindingList&lt;Department&gt; departments = repository.GetDepartments();
  
          dataGridView1.DataSource = departments;
          dataGridView1.Refresh();
  
      }
  }
  
  public class Department
  {
      public Department()
      {
          Employees=new BindingList&lt;Employee&gt;();
      }
      public string Name { get; set; }
      public BindingList&lt;Employee&gt; Employees { get; set; }
  }
  
  public class Employee
  {
      public string FullName { get; set; }
  }
  
  public class Repository
  {
      public BindingList&lt;Department&gt; GetDepartments()
      {
          var departments=new BindingList&lt;Department&gt;();
          departments.Add(new Department{Name = "Food"});
          departments.Add(new Department{Name = "Travel"});
          departments.Add(new Department{Name = "Beauty"});
          return departments;
      }
      public BindingList&lt;Employee&gt; GetEmployeeByDepartments(string name)
      {
          var employees = new BindingList&lt;Employee&gt;();
          switch (name)
          {
              case "Food":
                  employees.Add(new Employee { FullName = "Jim Bloggs1" });
                  employees.Add(new Employee { FullName = "Jim Bloggs2" });
                  break;
              case "Travel":
                  employees.Add(new Employee { FullName = "Marc Smith1" });
                  employees.Add(new Employee { FullName = "Marc Smith2" });
                  break;
              case "Beauty":
                    employees.Add(new Employee { FullName = "Mario XXX1" });
                    employees.Add(new Employee { FullName = "Mario XXX2" });
                  break;
  
          }
  
          return employees;
      }
  }
  </code></pre>