Wpf datagrid binding not updating

NET arena where I can force a data-rebinding by calling the Data Bind method of the object.

Oh well, I solved the problem, so I'm all sorts of happy.

Since the release of the WPF Data Grid there have been several common patterns of questions that developers were asking on the discussion list.

I thought that I would capture some of that here so it would be easy to find.

Normally my View Models inherit from my View Model Base base class, which provides a Raise Property Changed method and, when in debug mode, uses reflection to check if the property name is valid.

Now I’d recently refactored the code so this particular View Model wasn’t using the base class, so my first instinct was that I’d simply mistyped the property name magic string in the event – but that was all fine.

control, the underlying binding source is updated a soon as the control loses focus.

This is something you might want to prevent sometimes – a common scenario is a model dialog that provides a Cancel button to abort changes.

These days I generally work in C# and SQL, but in the past I’ve developed in everything from Assembly Language (68000 and x86) through to VB. I’ve also done my time in the support/engineering side of IT, so I’m pretty much a geek through and through 🙂 I’m a firm believer that reading and “best practices” are no substitute for using your brain!

So if you want to know the change in items of the collection you need to subscribe to the Collection Changed event of the Observable Collection But there is a problem with Observable Collection.

Collection Changed event – it does not fire when your data item’s property changes. That is if you have a collection of an Entity “Expense” that has properties “Name” and “Amount” and if you simply change the Amount value in the grid it does not work!

I’ll also try to keep it as short as possible and refer to other links for more information. Since a Data Grid Column has a Binding DP it is easy to think that bindings to other Data Grid Column DPs will work just the same but they don’t.

Below is an example showing a Data Grid Check Box Column setting the Binding DP and Can User Sort through data binding.

Leave a Reply