1.11M Members

How to get selected value in comboxcolumn of datagridview

 
0
 

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.

 
0
 

Could you please give your code?

 
0
 
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
            cmbcaste.Items.Add(rs.Fields(0).Value)
            rs.MoveNext()
        Loop
        dgvUserDetails.Columns.Add(cmbcaste)

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

 
0
 

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;
      try
      {
        for (int i = 0; i < numberRows; i++)
        {
          row++;
          column = -1;
          int numberColumns = dataGridView1.Columns.Count;
          for (int j = 0; j < numberColumns; i++)
          {
            column++;
            if (dataGridView1[row, column].Selected == true)
            {
              string strCellValue = dataGridView1[row, column].Value.ToString();
              dgwList.Add(strCellValue);
            }
          }
        }
      }
      catch
      {
        //catch an error!
      }
    }

Click Here

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article