1,105,295 Community Members

How to get selected value in comboxcolumn of datagridview

Member Avatar
Rachna0309
Light Poster
36 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
bazzer14
Newbie Poster
12 posts since May 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Could you please give your code?

Member Avatar
Rachna0309
Light Poster
36 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
atele
Newbie Poster
1 post since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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 three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article