Find attached the sample in Q382044 with a modification in the main view: I added a DataGrid and a ListBox that show the same data as the chart, and disabled the timer. Now, if I change any value of the "Date" or "Value" columns, the changes are reflected in both the grid and the listbox, but not in the chart. I expected the chart to be aware of the changes in the objects of the collection, just as the listbox and the grid are.
In the end I want an "Excel like" interface, in which you have a table with data and a chart next to it, and as you modify the values in the table the chart is updated.
Any way I can achieve this?
Thank you again, I really appreciate all your effort,
JM
If you modify the values in the table the chart is not updated
Answers
I have discussed this behavior with our developers. Chart drawing is a more resource-intensive operation than updating a text in DataGrid cells. So, we do not update the Chart control automatically when you edit an element of the collection, for performance reasons. You can update your Chart manually by using the UpdateData() method.
Alternatively, you can accomplish this task at the level of the ObservableCollection. Handle the PropertyChanged event of the collection items to call the OnCollectionChanged method:
C#internal class A : ObservableCollection<FinancialPoint>
{
protected override void InsertItem(int index, FinancialPoint item)
{
base.InsertItem(index, item);
((INotifyPropertyChanged)item).PropertyChanged += new PropertyChangedEventHandler(A_PropertyChanged);
}
protected override void RemoveItem(int index)
{
((INotifyPropertyChanged)this[index]).PropertyChanged -= new PropertyChangedEventHandler(A_PropertyChanged);
base.RemoveItem(index);
}
void A_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset, null));
}
}
Thank you for the suggestion. We appreciate your input. Once we make any decision in this regard, we will update this ticket accordingly. However, I cannot guarantee that we will implement this feature in the near future.
Thank you for evaluating my suggestion. Just to let you know, I implemented the derived ObservableCollection you suggested and it works perfectly! :-)
Thank you for informing us that the issue has been resolved. We are glad to hear that you have found a solution for this task.