winforms - How to get value from combobox in c#? -


i can't value combobox in winforms using c#.

i have combobox populated list of values , have set valuemember , displaymember.

now, have find value of selected combobox item , select matched item in ui.

here mean:-

i loaded combobox :-

var list = (from l in db.loc             orderby l.lname ascending             select l).tolist(); list.insert(0, new loc { id = "-1", name = "--select--" }); cmb1.bindingcontext = new bindingcontext(); cmb1.datasource = list; cmb1.displaymember = "name"; cmb1.valuemember = "id"; 

now on event, trying match value (id) , select item. it's easy if match text property:

cmb1.text = data.name; 

but how match value?

something this:-

cmb1.value = data.id; 

this should work:

cmb1.selectedvalue = data.id; 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -