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.
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.


Dillon Goeda22 reputationPosted Apr 6, 2013, 12:10 AM EDT
VulpesRank #55 · 29.2K reputationPosted Apr 6, 2013, 2:32 AM EDT
Try setting the comboBox1.SelectedText property instead of the SelectedItem property.
Violeta Popa132 reputationPosted Apr 6, 2013, 5:15 AM EDT
For exemple:
B1 discount 10
B2 adaos 5
B3 discount 10
if i select the first row, the cb shows discount, but if then i select the second row..doesn't show adaos, it's still discount :(
Dillon Goeda22 reputationPosted Apr 6, 2013, 5:34 AM EDT
Violeta Popa132 reputationPosted Apr 6, 2013, 5:59 AM EDT
VulpesRank #55 · 29.2K reputationPosted Apr 6, 2013, 6:10 AM EDT
comboBox1.SelectedText = "adaos";
select adaos?
If it doesn't, then possibly the value in the comboBox has some whitespace at the end?
Dillon Goeda22 reputationPosted Apr 6, 2013, 6:14 AM EDT
Private void dgv_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
int i= dgv.CurrentRow.Index;
comboBox1.SelectedItem = dgv.Rows[I].Cells[1].Value.ToString();
}
Or the same code in the button1_Click(...)
If I use the first code, it change everytime click on a new row