c# - ObservableCollection changing a value assigns a different value on same DataGrid row -


i wondering if possible assign value datagrid column when selectionchanged event combobox has been raised?

for example,

in combobox inside datagrid have 2 values of "0" , "1"

if user selects "0" - column inside grid , in same row called id show "0" if user decides select "1" id in same row change "1"

the other thing have data inside observablecollection, if combo 0, need id of 0 observablecollection.

i hope understandable.

------ code -------

        <datagrid.columns>             <datagridcomboboxcolumn selectedvaluebinding="{binding cid}" selectedvaluepath="cid"  header="cid" width="70">                 <datagridcomboboxcolumn.editingelementstyle>                     <style targettype="combobox">                          <!--<eventsetter event="selectionchanged" handler="abc"></eventsetter>-->                           <setter property="itemssource"                 value="{binding datacontext.entitycollection,                            relativesource={relativesource mode=findancestor,                                                      ancestortype=window}}"/>                         <setter property="displaymemberpath" value="cid"/>                      </style>                 </datagridcomboboxcolumn.editingelementstyle>                 <datagridcomboboxcolumn.elementstyle>                     <style targettype="combobox">                         <setter property="itemssource"                 value="{binding datacontext.entitycollection,                           relativesource={relativesource mode=findancestor,                                                       ancestortype=window}}"/>                         <setter property="displaymemberpath" value="cid"/>                     </style>                 </datagridcomboboxcolumn.elementstyle>                  <datagridcomboboxcolumn.headerstyle>                     <style targettype="{x:type datagridcolumnheader}">                         <setter property="horizontalcontentalignment"                             value="center" />                     </style>                 </datagridcomboboxcolumn.headerstyle>             </datagridcomboboxcolumn>                <datagridtextcolumn header="uid" binding="{binding entitycollection.uid}" width="70">             </datagridtextcolumn> 

so basically, want "uid" textcolumn updated whatever id collection user selects in cid combo box.

cheers

set combobox's selecteditem property bind member called selecteditem:

<datagridcomboboxcolumn selectedvaluebinding="{binding cid}" selecteditem="{binding selecteditem}" selectedvaluepath="cid"  header="cid" width="70"> 

then set member thats called selecteditem, this:

private int _selecteditem; public int selecteditem {    { return _selecteditem; }    set       {          _selecteditem = value;          onpropertychanged("selecteditem");       } } 

and in textbox, set binding selecteditem:

 <datagridtextcolumn header="uid" binding="{binding selecteditem.uid}" width="70">             </datagridtextcolumn> 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -