views:

737

answers:

1

I use MVVM for my project, the binding that set to DataTable work correctly at first time, but after I have update data on DataTable, it seem don't effect on DataGrid. Anyone know how to solving it?

A: 

Hard to say without more information and maybe some code (and I haven't used the WPF Toolkit grid - I use the Infragistics one.) A couple of things:

  • Are you notifying the UI of property changes (by implementing the INotifyPropertyChanged interface) in your MVVM classes?

  • You say "after you have updated data on DataTable". Updated how? Through the grid, or through some other means? Are your MVVM classes being "refreshed" correctly (and as such, informing the datagrid/UI that the data has changed)?

I've had varied luck with this stuff. Sometimes the Infragistics grid doesn't update if I add, say, an element to a collection programmatically. I pretty much have to re-read the whole thing for the grid to update. I haven't found the cause yet. Maybe you're dealing with a similar "anomaly" here.

Sorry, not necessarily helpful but maybe enough to point you in the right direction... Can't help much without more information.

MetalMikester
1. No, I don't implement INotifyPropertyChanged interface. I will try to implement it (on tomorrow).2. Update by command on ViewModel which bind to control on UI.
In The Pink
I haven't tried this approach (by command) yet, but it does look like it's just the UI that's not being informed that the underlying data has changed. You can do what you want in the background, but if the UI doesn't "get the memo", it won't update.
MetalMikester
I found the problem, forget to fire OnPropertyChanged but I have no idea how to implement it with DataTable.
In The Pink
I don't *think* you can use it directly on a DataTable object (I don't use DataTable.) Creating a class with properties corresponding to the appropriate columns, then building a collection of it from the DataTable might work though (the properties in the class would use OnPropertyChanged to notify the UI.)
MetalMikester
I meant *can't use it directly* above... D'OH!
MetalMikester