Updating a single item in a DataGrid

I have a simple problem that probably has a simple answer. I have a DataGrid displaying some elements. I want to update one of the following items:

var old = (SomeClass)grid.SelectedItem;
var newItem = new SomeClass(...);
old = newItem;
//grid.Items.Refresh();

Firstly, this code is trivialized in the example, but this is an important bit (the real problem is updating the object via Linq2Sql, and then setting the old object to the updated one).

Anyway, I was hoping the call Items.Refreshwould update the mesh interface, but that is not the case. Of course, I missed something regarding the way the DataGrid caches ItemsSource elements, but I would suggest that this is a fairly common scenario. Any idea?

+3
source share
2 answers

Item Item Grid ItemsSource. , .

, -

((IEnumerable)grid.ItemsSource)[grid.SelectedIndex] = newItem;  
+2

ItemsSource. , DependecyObject, INotifyPropertyChanged

+1

All Articles