I have datagridview which is populated with 8 columns also it is databound.Now my requirement is I need last column say ABC As comboboxcolumn.But if in database,this ABC column has some value for a particular row,then that value should be displayed in that row's cell as selected value.Please help me to solve this.Its urgent.

Dim cmbcaste As New DataGridViewComboBoxColumn()
        cmbcaste.Name = "Caste"
        cmbcaste.HeaderText = "Caste"
        sql = "Select Description from Category where Catgry = 1"
        If rs.State = 1 Then rs.Close()
        rs.Open(sql, MainCon, 1, 3)
        Do While Not rs.EOF

I have written above code but this is adding new column and also only filling combobox.

I am using combobox in datagridview.the combobox have both selected text and selected value.After selecting some rows i need to loop through the gridview and get selected text and selected value of each row.When I use dgSales["item",row].value i am getting only the selected value.I need the selected text also. Please give me a solution ..

private void button4_Click(object sender, EventArgs e)
      List<string> dgwList = new List<string>();
      int numberRows = dataGridView1.Rows.Count;
      int row = -1;
      int column = -1;
        for (int i = 0; i < numberRows; i++)
          column = -1;
          int numberColumns = dataGridView1.Columns.Count;
          for (int j = 0; j < numberColumns; i++)
            if (dataGridView1[row, column].Selected == true)
              string strCellValue = dataGridView1[row, column].Value.ToString();
        //catch an error!

Click Here

This article has been dead for over six months. Start a new discussion instead.