4
votes

I need help with a wpf datagrid using the MVVM design pattern.

I have a datagid that is bound to an observablecollection. The first column in the grid contains decimal values that cannot be edited. The second column contains a textbox into which a decimal value must be entered. The third column must display the difference between the value in the first column and the value in the second column AS IT IS ENTERED. I was hoping that handling the observablecollection's Collectionchanged event will allow met to determine when a field of one of the items in the collection has changed, but that does not seem to work.

I've also tried handling the PropertyChanged event of the grid's selected item, but that's not working either.

Can someone please indicate to me how to raise an event in the viewmodel whenever 'n value in a textbox, in a datagrid DataGridTemplateColumn, is changed? And then how do I set the calculated value in the third column's corresponding row?

1
Do the items in the ObservableCollection implement INotifyPropertyChanged?CodingGorilla
Are you also setting the UpdateSourceTrigger on the TextBox's binding?RMart
Hi. The item in the collection does implement INotifyPropertyChanged and the UpdateSourceTrigger=PropertyChanged for the datagrid as well as the textbox in the DataGridTemplateColumn.user823486

1 Answers

2
votes

You should try to tackle it from the other end (i..e from the ViewModel).

Your item(calling it CollectionItem) in the ObservableCollection should implement INotifyPropertyChanged.

You should tweak your grid so that data change is registered/commited as you change them (not on focus out/move)

and then in your CollectionItem should try to refresh the value based on the value change of input. let me know if you want more detail