combobox problem

  • Thread starter Thread starter drishtik
  • Start date Start date
D

drishtik

hi
i have a combobox which has some values loaded in it
like (eg)
a
b
c
d


i want to retrieve the value from the database (a, or b or c or d)
and then select that item in the combo according ly

foreach (DataRow dr in recs)
{
cmbType.SelectedText = dr["description"].ToString(); //there is only one
item here. is this the best way to iterate?
}

but this doesnt work
dr["description"] has the correct value ie b . and i want to select b in
the combo

i tried combo.selectedvalue and selectedtext but they dont work.
why and how do i solve this?

cmbType.SelectedText = dr["description"].ToString();
 
cmbType.Items.FindByText(dr["description"].ToString()).Selected = True

idog

Dan Cimpoiesu said:
Try
cmbType.SelectedValue=...

Regards
Dan Cimpoiesu

drishtik said:
hi
i have a combobox which has some values loaded in it
like (eg)
a
b
c
d


i want to retrieve the value from the database (a, or b or c or d)
and then select that item in the combo according ly

foreach (DataRow dr in recs)
{
cmbType.SelectedText = dr["description"].ToString(); //there is only one
item here. is this the best way to iterate?
}

but this doesnt work
dr["description"] has the correct value ie b . and i want to select b in
the combo

i tried combo.selectedvalue and selectedtext but they dont work.
why and how do i solve this?

cmbType.SelectedText = dr["description"].ToString();
 
Back
Top