We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to make a sfDataGrid cell to blink on value change ?

Hi,

I have a WinForms master-detail grid that is feed/updated by a MQTT stream of data, the data is correctly being displayed as it arrives, however I would like to provide to the user visual feed back of the cell just being update just briefly blinking its background or border, is it possible, like in many other sf controls, to do that ?

Thank you for your superb product and support.

5 Replies

AK Adhikesevan Kothandaraman Syncfusion Team July 3, 2019 01:40 PM UTC

Hi Luis, 

Thanks for using Syncfusion products. 

If you want to update the background color of the updated cell, you can use the QueryCellStyle and RecordPropertyChanged event as like the following code sample, 

Code Snippet: 
this.sfDataGrid1.QueryCellStyle += FirstLevelSourceDataGrid_QueryCellStyle; 
this.sfDataGrid1.View.RecordPropertyChanged += View_RecordPropertyChanged; 
private object rowData = null; 
private string propertyName; 
 
void View_RecordPropertyChanged(object sender, PropertyChangedEventArgs e) 
{ 
    rowData = sender; 
    propertyName = e.PropertyName; 
} 
 
private void FirstLevelSourceDataGrid_QueryCellStyle(object sender, Syncfusion.WinForms.DataGrid.Events.QueryCellStyleEventArgs e) 
{ 
    if (e.Column == null) return; 
 
    if (e.DataRow.RowData == rowData && e.Column.MappingName == propertyName) 
        e.Style.BackColor = Color.Green; 
} 
 
 

Regards, 
Adhi 



LF Luis Francisco July 3, 2019 08:56 PM UTC

Hi,

Thank you, this issue is NOT about how to change the cell background color. The issue is that the DATA CHANGES directly in the ObservableCollection, there I can set a property like  "shall_blink = true", and use it to BLINK-ON the cell on  the QueryCellStyle event.

The real issue now, is how to keep a pointer to that cell, so I can return the cell to its original color AFTER a few milliseconds and BLINK-OFF this cell, as the QueryCellStyleEventArgs does not provide sufficient info to the actual GridCell being painted, so I don´t know how to unpaint it using a delayed Task like in the snipped bellow:

        private void Grid_QueryCellStyle(object sender, QueryCellStyleEventArgs e)
        {
            if ((bool) e.DataRow.RowData.GetPropertyValue("shall_blink"))
            {
                Task.Run(() =>
                {
                    this.BeginInvoke(new Action(BlinkCell), new object[] { e });

                    void BlinkCell(QueryCellStyleEventArgs e2)
                    {
                        Color old_color = e2.Style.BackColor;
                        e2.Style.BackColor = Color.Yellow;
                        Task.Delay(250);
                        e2.Style.BackColor = old_color;
                    }
                });
            }
........




AK Adhikesevan Kothandaraman Syncfusion Team July 4, 2019 01:49 PM UTC

Hi Luis,  

Thanks for your update. 

If you want to change the particular cell value for the SfDataGird, you can use the property changed even and use the timer to update style and reset the properties. Please refer to the following code snippet and sample, 

Code Snippet: 
this.sfDataGrid1.QueryCellStyle += FirstLevelSourceDataGrid_QueryCellStyle; 
this.sfDataGrid1.View.RecordPropertyChanged += View_RecordPropertyChanged; 
propertyChangingTimer.Interval = 2000; 
propertyChangingTimer.Tick += propertyChangingTimer_Tick; 
 
private object rowData = null; 
private string propertyName; 
private Timer propertyChangingTimer = new Timer(); 
void View_RecordPropertyChanged(object sender, PropertyChangedEventArgs e) 
{ 
    rowData = sender; 
    propertyName = e.PropertyName; 
    propertyChangingTimer.Start(); 
} 
 
void propertyChangingTimer_Tick(object sender, EventArgs e) 
{ 
    propertyChangingTimer.Stop(); 
 
    //Reset the properties on the timer tick. 
    propertyName = string.Empty; 
    rowData = null; 
    this.sfDataGrid1.TableControl.Invalidate(); 
} 
 
private void FirstLevelSourceDataGrid_QueryCellStyle(object sender, Syncfusion.WinForms.DataGrid.Events.QueryCellStyleEventArgs e) 
{ 
    if (e.Column == null) return; 
 
    if (e.DataRow.RowData == rowData && e.Column.MappingName == propertyName) 
        e.Style.BackColor = Color.Green; 
} 

 

Regards, 
Adhi 




LF Luis Francisco July 4, 2019 03:42 PM UTC

Perfect !!! Thank you so much.


FP Farjana Parveen Ayubb Syncfusion Team July 5, 2019 05:35 AM UTC

Hi Luis, 
 
Thanks for the update. 
 
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you. 
 
Regards, 
Farjana Parveen A 


Loader.
Live Chat Icon For mobile
Up arrow icon