Travis Banger
Travis Banger

Reputation: 717

WPF DataGrid: Need Binding to Occur ASAP

I was having the delayed-binding problem mentioned here:

WPF DataGrid source updating on cell changed

My source properties were being updated when the user pressed Enter but not when s/he pressed Tab.

I found an excellent advice in the post above: UpdateSourceTrigger=LostFocus (that is the answer with most upclicks, BTW) and now the updates are done as desired, when the user leaves the cell horizontally or vertically. One problem remains, however: pressing Enter while in the bottom row.

The relevant columns are defined as follows:

<DataGridTextColumn Header="Quantity" 
                    Width="Auto" 
                    Binding="{Binding Path=Quantity, 
                              UpdateSourceTrigger=LostFocus}">
</DataGridTextColumn>

Isn't there something like: UpdateSourceTrigger=EditEnded ??

Posterior addition:

The Explicit option seems quite promising:

http://msdn.microsoft.com/en-us/library/system.windows.data.binding.updatesourcetrigger%28v=vs.100%29.aspx

My event handler would only care about events triggered by the last row and call the UpdateSource method. If that is the solution, I only need to know what to place to the left of .UpdateSource().??

Upvotes: 0

Views: 169

Answers (1)

Fede
Fede

Reputation: 44038

Just tried this:

   <DataGridTextColumn Header="Quantity" 
                       Width="Auto" 
                       Binding="{Binding Path=Quantity,  UpdateSourceTrigger=PropertyChanged}">
   </DataGridTextColumn>

And it works fine. The binding is updated on every key press, rather than when changing the row or else.

Upvotes: 1

Related Questions