Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

DataGrid and persisting on cell lost focus

$
0
0

I need to persist the value of a cell when the user leaves it. This sounds like a quite normal use case but apparently this isn't very Google’able.

I have a working solution using the DataGrid_CellEditEnding and delaying  the persisting logic on the Dispatcher since the model hasn’t been updated yet.

There must be other ways to do this!?

privatevoid DataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)

{

   Action action = () =>

    {

       var row = e.Row.ItemasMyRow;

        row.RootModel.Save(row);

    };

   //TODO : WTF! :)

   //we need to execute this on the gui queue, since the viewmodel has not been updated yet!

   //http://stackoverflow.com/questions/2094615/textchanged-lostfocus-etc-event-for-datagridtextcolumn

    Dispatcher.BeginInvoke(action,DispatcherPriority.ContextIdle);

}


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>