Violeta Popa

Violeta Popa

  • NA
  • 137
  • 163.7k

comboBox doesn't work properly

Apr 6 2013 3:49 AM
Hello :) I have a datagridview in form 1 and in form 2 a comboBox. I want to select an item from the comboBox depending on a cell from dgv. Here's the code

SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "..";
            conn.Open();

            Acasa main = (Acasa)Application.OpenForms["Acasa"];
            DataGridView dgv = main.categdaGridView;
            int i = dgv.CurrentRow.Index;
       
            textBox1.Text = dgv.Rows[i].Cells[1].Value.ToString();
            textBox3.Text = dgv.Rows[i].Cells[3].Value.ToString();
            comboBox1.SelectedItem = dgv.Rows[i].Cells[2].Value.ToString();

            conn.Close();

but the comboBox doesn't select nothing :| if i do comboBox1.SelectedItem="discount" it works, and i checked dgv.Rows[i].Cells[2].Value.ToString(); has the same value(discount). Does anybody know what could cause it? Thank u very much.

Answers (7)