We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,931 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to get selected value in comboxcolumn of datagridview

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.

3
Contributors
3
Replies
1 Hour
Discussion Span
4 Months Ago
Last Updated
4
Views
Rachna0309
Light Poster
36 posts since Nov 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Could you please give your code?

bazzer14
Newbie Poster
12 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 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.

Rachna0309
Light Poster
36 posts since Nov 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 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

atele
Newbie Poster
1 post since Jan 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0742 seconds using 2.7MB