SfDataGrid Update Itemsources

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!


Attachment: mms_101ff260.zip

5 Replies 1 reply marked as answer

DM Dhanasekar Mohanraj Syncfusion Team July 18, 2022 04:04 PM UTC

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.


Attachment: Modified_sample_a9015608.zip


NT NGUYEN THANH DAT replied to Dhanasekar Mohanraj July 19, 2022 02:20 AM UTC

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!


Attachment: Thanh_Update_19Jul_a8fbc228.zip


DM Dhanasekar Mohanraj Syncfusion Team July 19, 2022 04:22 PM UTC

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.


Attachment: Thanh_Update_19Jul_43156da4.zip

Marked as answer

NT NGUYEN THANH DAT replied to Dhanasekar Mohanraj July 20, 2022 06:22 AM UTC

It works~ 

Thank you so much!

Have a wonderful day~~



DM Dhanasekar Mohanraj Syncfusion Team July 21, 2022 02:12 PM UTC

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.


Loader.
Up arrow icon