c# - Datagrid Binding to ObservableCollection WPF -


i have datagrid binding observablecollection source, data grid cells allowed user change values, problem when change cells values observablecollection not update

here's datagrid code :

<datagrid.columns>     <datagridtextcolumn header="item" binding="{binding item.itemname,mode=twoway}" width="100" isreadonly="false" />     <datagridtextcolumn header="price" binding="{binding saleprice,mode=twoway}" width="100" isreadonly="false"  />     <datagridtextcolumn header="qtn" binding="{binding quantity,mode=twoway}" width="100" isreadonly="false"  />     <datagridtextcolumn header="totla" binding="{binding total,mode=twoway}" width="100" isreadonly="false"  /> </datagrid.columns> 

any suggestions

the wpf datagrid uses transaction scope when cells edited. means after changing cell, 'commit' needed in order persist change. force commit, can use tab key or enter key.

lots of people type new value cell , mouse cell or control altogether. when happens datagrid 'cancel' on transaction , change not persisted in underlying collection. in fact, other tab or enter (or losing focus) raise cancel on transaction.

if want capture changes regardless of key user pressed, underlying class should implement ieditableobject. allows view model force commit , persist changed cell.

it's known 'gotcha' on wpf datagrids. there's lucid discussion on here http://blogs.msdn.com/b/vinsibal/archive/2009/04/07/5-random-gotchas-with-the-wpf-datagrid.aspx

even more subtle 'gotchas' on same subject discussed here http://blogs.msdn.com/b/vinsibal/archive/2009/04/14/5-more-random-gotchas-with-the-wpf-datagrid.aspx

possible duplicate of why isn't property in viewmodel updated when datagrid changes?


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -