7
Answers

comboBox doesn't work properly

Violeta Popa

Violeta Popa

11y
1.5k
1
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)