c# - In a WPF datagrid, how do I get the new row after cell edit? -
my datagrid
bound datatable
. after each cell edit in grid, need new datarow
value. new values after focus lost row , not cell.
<datagrid itemssource="{binding}" celleditending="grid_celleditending"/> private void grid_celleditending(object sender, datagridcelleditendingeventargs e) { //both datatable , row obtained "e" has old row. }
what should new datarow
?
as name hints, celleditending
event gets fired right before edit commited. sadly, since there no celleditended event, there's no straightforward way want.
you have 3 options here:
- set cell's bindings
updatesourcetrigger
propertychanged
, changes applied on fly instead of waiting commit. - set cell's bindings
notifyonsourceupdated
true
, addbinding.addsourceupdatedhandler(mydatagrid,ondatagridsourceupdated)
in code-behind (look here more info: http://wpf.codeplex.com/discussions/39356). - or handle both
celleditending
,roweditending
events. in celleditending, usedispatcher.begininvoke
forcedatagrid.commitedit()
call. , in roweditending, usebegininvoke
again execute code. it'll execute after row edit has been commited, you'll have manually retrieve row value index or (check similar example here (point 5): http://blogs.msdn.com/b/vinsibal/archive/2009/04/14/5-more-random-gotchas-with-the-wpf-datagrid.aspx) - keep in mind since don't have control on when code executed, items have changed further, rearranged or that, isn't 100% reliable without work part.
Comments
Post a Comment