c# - Change selection WPF combobox by variable -


i'm using combobox show categories user can choose.

enter image description here

all items have id selectedvaluepath can easly when user makes selection.

<combobox grid.column ="1" grid.row="1" horizontalalignment="center" verticalalignment="center" width="200" name="cbocategorieen" itemssource="{binding}" displaymemberpath="naam" selectedvaluepath="id" /> 

but how can change selection of combobox when have id of chosen selection (selectedvaluepath)? code doesn't , keeps selecting first one.

cbocategorieen.selectedvaluepath = convert.tostring(artikelwijzigen.categorie); 

to conclude: how can change selection of combobox 1 matching id?

i suggest follow mvvm, still answer question if have itemssource this,

observablecollection<yourcomboboxclass> wswebshopmrentals; 

you can set selecteditem of combobox this,

cbocategorieen.selectedvalue = wswebshopmrentals.firstordefault(x => x.id == yourid).naam; 

Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -