title: Add a combo box in a specific row in datagrid view c#
body: <p>I want to have a combobox in a specific cell in my data grid view. can somebody help? For the table I'm using data table</p>
  
  <p>Problem: I want to put a combobox in a specific cell like in column 1 and row 1.  </p>
  
  <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>
  
  <p>here is my whole code----</p>
  
  <pre><code>public partial class Form1 : Form
      {
          String line;
          String typeOfTable;
          int amountOfTablesInTab;
  
  
          delegate void SetComboBoxCellType(int iRowIndex);
  
          bool bIsComboBox = false;
  
          List&lt;TabPage&gt; tapPages = new List&lt;TabPage&gt;();
  
          TabPage myTabPage;
          DataGridView RunTimeCreatedDataGridView; 
  
  
          private const String TABS = "TABS";
          private const String TABLES = "TABLES";
          private const String GRID = "grid";
          private const String LIST = "list";
  
          private const int LOCATION_TABLE_TYPE = 2;
          private const int LOCATION_TABLE_AMOUNT_ROWS = 3;
          private const int LOCATION_TABLE_AMOUNT_COLUMNS = 4;
          private const int AMOUNT_COLUMNS_IN_LIST = 2;
          private const int LOCATION_TAB_FOR_TABLE = 1;
          private const int STARTING_POSITION_FOR_TABLES = 5;
          private const int TABLE_SIZE= 205;
  
          String[] splitTableArray;
          List&lt;String&gt; tabList = new List&lt;String&gt;();
          List&lt;String&gt; tablesList = new List&lt;String&gt;();
  
          public Form1()
          {
              InitializeComponent();
              //test();
             getFormContentFromFile();   
          }
  
          private void getFormContentFromFile()
          {
              using (StreamReader reader = new StreamReader("neo2G.res"))
              {
                  while (!reader.EndOfStream)
                  {
                      line = reader.ReadLine();
  
                      if (line.Equals(TABS))
                      {
  
                          while (!line.Equals(".."))
                          {
                              line = reader.ReadLine();
  
  
                              if (!line.Equals("..") &amp;&amp; !line.Equals(""))
                              {
                                  tabList.Add(line);
                              }
  
                          }
                      }
  
                      if (line.Equals(TABLES))
                      {
                          while (!line.Equals(".."))
                          {
                              line = reader.ReadLine();
  
                              if (!line.Equals(".."))
                              {
  
                                  tablesList.Add(line);
  
                              }
                          }
                      }
                  }
  
                  createTablesInTab();
  
              }
          }
  
          private void searchTablesToMatch(int tabCount)
          {
                   int tableCount = 0;
              int tabLocationForTables;
              amountOfTablesInTab = 0;
  
  
              foreach(String table in tablesList)
              {
                  splitTableLineToArray(tablesList[tableCount]);
  
                  if (int.TryParse(splitTableArray[LOCATION_TAB_FOR_TABLE], out tabLocationForTables))
                  {
  
                      if(tabLocationForTables == tabCount)
                      {
                          typeOfTable = splitTableArray[LOCATION_TABLE_TYPE];
                          amountOfTablesInTab++;
  
  
                          if(typeOfTable.Equals(LIST))
                          {
  
                              createListInForm(int.Parse(splitTableArray[LOCATION_TABLE_AMOUNT_ROWS]));
  
                          }
  
                          else if(typeOfTable.Equals(GRID))
                          {
  
  
                              createGridInForm(int.Parse(splitTableArray[LOCATION_TABLE_AMOUNT_ROWS]), int.Parse(splitTableArray[LOCATION_TABLE_AMOUNT_COLUMNS]));
                          }
                      }
                  {
  
                  }
                  }
                  else
                  {
                      MessageBox.Show("The format for TABLES must be identical to the table format in the Configuration file format", "File Error", 
                      MessageBoxButtons.OK, MessageBoxIcon.Error);
                  }
                  tableCount++;
              }
          }
  
          private int getLocationForTable()
           {
               int position = 0;
  
               for (int i = 1; i &lt;= amountOfTablesInTab; i++)
               {
                   position = position + TABLE_SIZE;
  
                   if (i == 1)
                   {
                       position = STARTING_POSITION_FOR_TABLES;
                   }
               } 
             return position;
          }
  
  
          private void createGridInForm(int rows, int columns)
          {
  
              RunTimeCreatedDataGridView = new DataGridView();
              DataGridViewComboBoxCell c = new DataGridViewComboBoxCell();
              myTabPage.Controls.Add(RunTimeCreatedDataGridView);
  
  
              c.Items.Add("A");
              c.Items.Add("B");
              c.Items.Add("C");
  
  
              RunTimeCreatedDataGridView.DataSource = createGridForForm(rows, columns);
              //Assign it to your dataGridView
              RunTimeCreatedDataGridView.Rows[1].Cells[1] = c;
  
  
              int positionForTable = getLocationForTable();
              RunTimeCreatedDataGridView.BackgroundColor = Color.WhiteSmoke;
  
              RunTimeCreatedDataGridView.Size = new Size(995, 200);
              RunTimeCreatedDataGridView.Location = new Point(5, positionForTable);
  
  
  
  
  
          }
  
          private void createListInForm(int rows)
          {
              RunTimeCreatedDataGridView = new DataGridView();
              RunTimeCreatedDataGridView.DataSource = createListForForm(rows);
              int positionForTable = getLocationForTable();
              RunTimeCreatedDataGridView.BackgroundColor = Color.WhiteSmoke;
  
  
              RunTimeCreatedDataGridView.Size = new Size(995, 200);
              RunTimeCreatedDataGridView.Location = new Point(5, positionForTable);
              myTabPage.Controls.Add(RunTimeCreatedDataGridView);
          }
          private void createTablesInTab()
          {
               int countTab = 0;
  
              foreach (String tab in tabList)
              {
  
                  countTab++;
                  createTabInForm(tab);
                  searchTablesToMatch(countTab);
                 }
  }
  
          private void createTabInForm(String tabName)
          {
              tabName = Regex.Replace(tabName, @"[\d-]", string.Empty);
              tabName = tabName.Trim(':', '"');
              myTabPage = new TabPage(tabName);
              tabControl1.TabPages.Add(myTabPage);
  
              myTabPage.AutoScroll = true;
  
          }
  
          private void splitTableLineToArray(String tableLine)
          {
              splitTableArray = tableLine.Split(',');
          }
  
          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
  
                  table.Rows.Add(dr);
  
  
              }
  
              return table;
          }
  
  
          public DataTable createListForForm(int rows)
          {
  
              // Create the output table.
              DataTable table = new DataTable();
  
  
              for (int i = 1; i &lt;= AMOUNT_COLUMNS_IN_LIST ; 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
  
                  table.Rows.Add(dr);
  
  
                 }
  
              return table;
          }
  
      } 
  </code></pre>