title: Putting a listbox/dropdown menu in a data grid view C#
body: <p>I have a data table in a data grid view. I want to put an listbox/dropdown menu in a specific column and row. I have tried this but it doesn't work --</p>
  
  <pre><code>var column = new DataGridViewComboBoxColumn();
              RunTimeCreatedDataGridView[1, 1].Value = RunTimeCreatedDataGridView.Columns.Add(column); 
  </code></pre>
  
  <p>Here is how I populate the table--</p>
  
  <pre><code>public DataTable createGridForForm(int rows, int columns)
  {              
      // Create the output table.
      DataTable table = new DataTable();
  
      for (int i = 1; i &lt;= columns; i++)
      {
          table.Columns.Add("column " + i.ToString());
      }
  
      for (int i = 1; i &lt; rows; i++)
      {
          DataRow dr = table.NewRow();
          // populate data row with values here
          ListBox test = new ListBox();
          myTabPage.Controls.Add(test);
          table.Rows.Add(dr);
      }
      return table;
  }
  </code></pre>
  
  <p>And here is how I create the datagridview.</p>
  
  <pre><code>private void createGridInForm(int rows, int columns)
  {
      DataGridView RunTimeCreatedDataGridView = new DataGridView();
      RunTimeCreatedDataGridView.DataSource = createGridForForm(rows, columns);
  
      //DataGridViewColumn ID_Column = RunTimeCreatedDataGridView.Columns[0];
      //ID_Column.Width = 200;
  
      int positionForTable = getLocationForTable();
      RunTimeCreatedDataGridView.BackgroundColor = Color.WhiteSmoke;
  
      RunTimeCreatedDataGridView.Size = new Size(995, 200);
      RunTimeCreatedDataGridView.Location = new Point(5, positionForTable);
      myTabPage.Controls.Add(RunTimeCreatedDataGridView);                   
  }
  </code></pre>