Hi,
I am using SfDataGrid to show the List of objects by set the ItemSources in C# code.
When I update the ItemSources by button the data on Grid is not updated.
I have reproduced the problem as attached. Could you please help me to check it?
Working sequence: File > New > File > Import
Thanks, and Best Regards!
Hi NGUYEN THANH DAT,
We regret to let you know that we are a little unclear about the scenario. We have checked the reported issue with the provided sample. If you are using the ItemsSource as List, SfDataGrid will not refresh the UI automatically we have also mentioned this in our user guide documentation as a limitation.
For more information related to binding the list as ItemsSource, please refer to the below user guide documentation link,
UG Link: https://help.syncfusion.com/wpf/datagrid/data-binding
If you are using ObservableCollection UI will update properly as expected. Please find the modified sample in the attachment and revert us if you need further assistance with this.
Regards,
Dhanasekar M.
Hi Mohanraj,
Thank you for your response!
As your suggestion, I am using ObservableCollection. But when I update the Collection item value, the DataGrid is not update value. I updated the project as attached.
Could you please help me to check the void "CheckTag" at line 53 in "MainWindow.xaml.cs"? I updated the image source and Min value in the "CheckTag" function.
private void CheckTag()
{
List<string> AvaiNode = new List<string>() { "G1", "G3", "G6" };
//foreach (var item in ListTagInfo)
//{
// if (AvaiNode.Contains(item.NodeID))
// {
// item.StatusImage = StatusGreen;
// }
// else
// {
// item.StatusImage = StatusRed;
// }
//}
for (int i = 0; i < ListTagInfo.Count; i++)
{
if (AvaiNode.Contains(ListTagInfo[i].NodeID))
{
ListTagInfo[i].StatusImage = StatusGreen;
ListTagInfo[i].Min = 100;
}
else
{
ListTagInfo[i].StatusImage = StatusRed;
}
}
//dataGrid.ItemsSource = ListTagInfo;
}
Working sequence: File > New, File > Check.
Thanks, and best regards!
Hi NGUYEN THANH DAT,
You can achieve your requirement by implementing the INotiFyPropertyChanged interface for the model class. Please refer to the below code snippet,
|
public class ModelTagInfo : INotifyPropertyChanged { private BitmapImage statusImage; public BitmapImage StatusImage { get { return statusImage; } set { statusImage = value; RaisePropertyChanged("StatusImage"); } }
public event PropertyChangedEventHandler PropertyChanged; public void RaisePropertyChanged(string name) { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(name));
} } |
Please find the modified sample in the attachment and let us know if you have any concerns about this.
Regards,
Dhanasekar
M.
It works~
Thank you so much!
Have a wonderful day~~
Hi NGUYEN THANH
DAT,
If you are satisfied
with our response, please mark it as an answer. Otherwise, please let us know
if you have any further queries on this. We are happy to help you.
Regards,
Dhanasekar M.