title: Creating column Combobox in Datagridview
body: <p>I am new to <code>C#</code>. I want to create <code>combobox</code> in first column of my <code>Datagridview</code>. Following is the routine I have wrote. But it is adding combo in last column after setting up my grid.</p>
  
  <p>For setting up Grid, i have tried the below code:</p>
  
  <pre><code>private void SetGrid()
  {
      dgDetail.AutoGenerateColumns = false;
      dgDetail.ColumnCount = 5;
      dgDetail.Columns[0].Name = "Debit";
      dgDetail.Columns[0].HeaderText = "Debit Account Name";
      dgDetail.Columns[1].Name = "Bank";
      dgDetail.Columns[1].HeaderText = "Bank";
      dgDetail.Columns[2].Name = "ChqNo";
      dgDetail.Columns[2].HeaderText = "CC/Chq No";
      dgDetail.Columns[3].Name = "ChqDate";
      dgDetail.Columns[3].HeaderText = "Chq Date";
      dgDetail.Columns[4].Name = "Amount";
      dgDetail.Columns[4].HeaderText = "Amount";
      dgDetail.AllowUserToDeleteRows = true;
      dgDetail.Columns[0].Width = 280;
      dgDetail.Columns[1].Width = 160;
      dgDetail.Columns[2].Width = 90;
      dgDetail.Columns[3].Width = 90;
      dgDetail.Columns[4].Width = 120;
      dgDetail.RowsDefaultCellStyle.ForeColor = Color.Black;
      dgDetail.RowsDefaultCellStyle.BackColor = Color.White;
      dgDetail.Font = new Font("Arial", 9, FontStyle.Regular);
  }
  </code></pre>
  
  <p>For Creating the combobox which is filled from DB.</p>
  
  <pre><code>private void FillGridCombo()
  {
      SqlConnection sqlConnection = new SqlConnection(strCon);
      sqlConnection.Open();
      try
      {
          string selectQueryStringMonth = "SELECT accode, GLAC FROM glmast where (actype = 'CSH' and titleac &lt;&gt; 'PDP') OR TITLEAC = 'DIS' ORDER BY GLAC";
  
          SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(selectQueryStringMonth, sqlConnection);
          SqlCommandBuilder sqlCommandBuilder = new SqlCommandBuilder(sqlDataAdapter);
  
          DataTable dataTable = new DataTable();
          sqlDataAdapter.Fill(dataTable);
          BindingSource bindingSourceMonth = new BindingSource();
          bindingSource.DataSource = dataTable;
  
          //Adding  Combo
          DataGridViewComboBoxColumn ColumnAcc = new DataGridViewComboBoxColumn();
          ColumnAcc.DataPropertyName = "Debit Account Name";
          ColumnAcc.HeaderText = "Debit Account Name";
          ColumnAcc.Width = 280;
  
          ColumnAcc.DataSource = bindingSourceMonth;
          ColumnAcc.ValueMember = "accode";
          ColumnAcc.DisplayMember = "GLAC";
  
          dgDetail.Columns.Add(ColumnAcc);
          dgDetail.DataSource = bindingSource;
      }
  
      catch (Exception ex)
      {
          MessageBox.Show("Error : " + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
      }
  
      finally
      {
          if (sqlConnection.State != ConnectionState.Closed)
          sqlConnection.Close();
      }
  }
  </code></pre>
  
  <p>I am calling both procedures on my NewData() like this.</p>
  
  <pre><code>private void NewData()
  {
      if (dgDetail.DataSource != null)
          dgDetail.DataSource = null;
      else
          dgDetail.Rows.Clear();
  
      ClearData();
      CtrlEnable();
      SetGrid();
      FillGridCombo();
  }
  </code></pre>
  
  <p>Help / Guide me to achieve this.,</p>