c# - DataGridComboBoxColumn binding -
i have seen few posts on here people getting confused on how bind datagridcomboboxcolumn,
i have
<datagridcomboboxcolumn selecteditembinding="{binding collection}" displaymemberpath="name" header="name" width="70">
which didnt work..
so used
<datagridcomboboxcolumn itembinding="{binding collection}" displaymemberpath="name"> header="name" width="70">
which again didn't work, why binding datagridcombo different original combo box.
<combobox itemssource="{binding collection}" displaymemberpath="name" horizontalalignment="left">
which work
what correct method of binding combo box inside datagrid?
---edit---
i might have found problem, have datagrid binding itemsource, however, want comboboxcolumn bounded different itemsource, possible?
cheers
you need bind itemssource
property. set in editingelementstyle
.
<datagridcomboboxcolumn> <datagridcomboboxcolumn.editingelementstyle> <style targettype="combobox"> <setter property="itemssource" value="{binding collection}"/> <setter property="displaymemberpath" value="name"/> </style> </datagridcomboboxcolumn.editingelementstyle> </datagridcomboboxcolumn>
in case want itemssource
bind collection outside of datagrid underlying source object, can well.
say have collection anothercollection
residing in viewmodel of window/usercontrol, can bind using relativesource
markup extension.
also, have set selecteditembinding
property want set value selected combobox , declare same style under elementstyle of datagridcomboboxcolumn. suppose property name name
want bind.
<datagridcomboboxcolumn selecteditembinding="{binding name}"> <datagridcomboboxcolumn.editingelementstyle> <style targettype="combobox"> <setter property="itemssource" value="{binding datacontext.anothercollection, relativesource={relativesource mode=findancestor, ancestortype=window}}"/> <setter property="displaymemberpath" value="name"/> </style> </datagridcomboboxcolumn.editingelementstyle> <datagridcomboboxcolumn.elementstyle> <style targettype="combobox"> <setter property="itemssource" value="{binding datacontext.anothercollection, relativesource={relativesource mode=findancestor, ancestortype=window}}"/> <setter property="displaymemberpath" value="name"/> </style> </datagridcomboboxcolumn.elementstyle> </datagridcomboboxcolumn>
Comments
Post a Comment