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:

  1. set cell's bindings updatesourcetrigger propertychanged, changes applied on fly instead of waiting commit.
  2. set cell's bindings notifyonsourceupdated true , add binding.addsourceupdatedhandler(mydatagrid,ondatagridsourceupdated) in code-behind (look here more info: http://wpf.codeplex.com/discussions/39356).
  3. or handle both celleditending , roweditending events. in celleditending, use dispatcher.begininvoke force datagrid.commitedit() call. , in roweditending, use begininvoke 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

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -