I fill a grid view with data. When some of that data changes I would like the changed data to update the grid view without having to rebind the grid view. From my understanding I should be able to do this by implementing INotifyPropertyChanged, but I can't get it to work.
When I debug, in the OnPropertyChanged function the PropertyChanged event is null so it doesn't fire. I assume I have to do something when I bind to the grid to wire up the property changed event, but I can't figure out what that is. Any help on what I need to do to get the PropertyChanged event to update the grid?
I bind the grid column like this:
_gridViewResults.Columns.Add(
new GridColumn()
{
Width = 60,
HeaderText = "Instances",
DataCell = new TextBoxCell { Binding = Binding.Property<SearchableItem, string>(o => o.Instances) }
});
and later set the data like this:
_gridViewResults.DataStore = DoSearch(_textBoxSearch.Text); // This returns an ObservableCollection of SearchableItems
SearchableItem implements INotifyPropertyChanged like this:
public class SearchableItem : INotifyPropertyChanged
{
public string Instances
{
get { return _instances; }
set
{
_instances = value;
OnPropertyChanged(new PropertyChangedEventArgs("Instances"));
}
}
private string _instances = "";
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(PropertyChangedEventArgs e)
{
if (PropertyChanged != null)
{
PropertyChanged(this, e);
}
}
}
Thanks!