[Solved] Adding an item to a List which is DataBinded to a DataGrid


Are you adding items to the data bound List<CustomClass> on a background thread? Then you could use the dispatcher to marshall the Add call to back the UI thread:

Application.Current.Dispatcher.BeginInvoke(new Action(()=> { yourCollection.Add(yourItem); })));

Do this for all Add and Remove operations that modify the source collection.

You should also replace the List<CustomClass> with an ObservableCollection<> if you want the DataGrid to get updated automatically as items are added to the source collection. An ObservableCollection provides change notifications but a List doesn’t: http://msdn.microsoft.com/en-us/library/ms668604%28v=vs.110%29.aspx.

Also make sure that you are adding items to the source collection rather than to the Items property of the DataGrid control.

0

solved Adding an item to a List which is DataBinded to a DataGrid