Manually updating a cell

Hi,



I am struggling to find any articles on the problem I am facing.



Basically I am binding a data source to the grid using datagrid.ItemsSource = myCollection when the data is ready through an event handler

in my grid XAML, I have a bunch of UnboundColumns which get populated with the content of the data when I perform the binding, with one specific column populating an image from a URL implementing IValueConverter. So far so good everything working as expected.



Now the problem I have is that when the data source is changed through the event handler notification the only way to refresh the grid with the new data seems to be by rebinding again datagrid.ItemsSource = myCollection or datagrid.view.refresh() which I am trying to avoid doing since the whole image is repopulated and causing the grid to flicker, especially when only 2 columns are changing values with no new rows or deleted rows. So ideally I would like to simply populate on my event handler these 2 columns with something like datagrid[row, col] = mydatasource[row].property1 - 



so basically is there any way to assign manually a cell value - so without using MVVM INotifyPropertyChanged



Thanks in advance


2 Replies

MO Mohamed July 28, 2018 11:44 AM UTC

i managed to get it working by using a static list of images and ignoring the Convert in IValueConverter if the image is already in the list. Not very clean though.


SJ Sathiyathanam Jeyakumar Syncfusion Team July 30, 2018 09:47 AM UTC

Hi Mohamed, 
 
We have analyzed your query. Whenever we change the cell value programmatically, then it will change based on the updated value by using the change notification of that property.  The change notification will be called for the property by implementing the INotifyPropertyChanged interface.  Without any notification, the property value will not be changed/updated in UI. If you don’t want to implement the INotifyPropertyChanged interface, then you can raise the event for the property like below, 
 
public class OrderDetails 
{ 
       private int _OrderID; 
 
       public int OrderID 
       { 
            get  
            { 
                return this._OrderID;  
            } 
            set 
            { 
                this._OrderID = value; 
                if (OrderIDChanged != null) 
                    OrderIDChanged(this, EventArgs.Empty); 
            } 
        } 
 
        public event EventHandler OrderIDChanged; 
 
} 
 
Button click code:  
private void button_Click(object sender, RoutedEventArgs e) 
{ 
       var record = this.sfdatagrid.View.Records.GetItemAt(2); 
       var orderInfo = record as OrderDetails; 
       orderInfo.OrderID = 5000; 
} 
 
In this case, you need to handle the event for each property which you want to update. 
 
 
 
In the above sample you can change the OrderID value of the second recond using the button click event. (Whithout implementing the INotifyPropertyChanged interface). 
 
Regards, 
Sathiyathanam

Loader.
Up arrow icon