Refresh cell style after edit

Hi,

My need is to update the style of a cell. I use a style selector:

protected override Style SelectStyleCore(object item, DependencyObject container)
        {
            if(container is TreeGridCell && ((TreeGridCell)container).Content is TextBlock)
            {
                TextBlock textBlock = ((TreeGridCell)container).Content as TextBlock;
                string cellText = textBlock.Text;
                if (EqualsToZero(item, container))
                {
                    return App.Current.Resources["cellStyleZero"] as Style;
                }
                if (item is Group || item is GroupComponent)
                {
                    return App.Current.Resources["cellStyleBold"] as Style;
                }
            }
            return App.Current.Resources["cellStyle"] as Style;
        }

But I noticied this code is not fired when I edit the cell. How can I refresh the style when I edit? I tried this:

private void TreeGridLines_CurrentCellEndEdit(object sender, CurrentCellEndEditEventArgs e)
        {
            try
            {
                if (((SfTreeGrid)sender).CurrentItem is Group)
                {
                    Group group = (Group)((SfTreeGrid)sender).CurrentItem;
                    saveGroup.ModifyElt(new Group(group));
                }
                else if (((SfTreeGrid)sender).CurrentItem is Line)
                {
                    Line line = (Line)((SfTreeGrid)sender).CurrentItem;
                    UpdateFields(line);
                    saveLine.ModifyElt(new Line(line));
                    
                }
            treeGridLines.View.Refresh();
            }
            catch(Exception ex)
            {

            }
        }

But treegrid collaps all nodes and focus is lost.

3 Replies 1 reply marked as answer

MA Mohanram Anbukkarasu Syncfusion Team February 5, 2021 01:06 PM UTC

Hi Daniel, 

Thanks for contacting Syncfusion support.  

You can achieve your requirement to refresh the cells to apply the style based on CellStyleSelector after editing the value by calling SfTreeGrid.UpdateDataRow in the SfTreeGrid.CurrentCellEndEdit event as shown in the following code example.  

Code example :  

using Syncfusion.UI.Xaml.TreeGrid.Helpers; 
 
private void TreeGrid_CurrentCellEndEdit(object sender, CurrentCellEndEditEventArgs e) 
{ 
    this.treeGrid.UpdateDataRow(e.RowColumnIndex.RowIndex); 
} 


Please let us know if you require further assistance from us.  

Regards, 
Mohanram A. 


Marked as answer

DG Daniel Garcia February 8, 2021 06:50 AM UTC

Hi Mohanram,

I tried it and it's works well, thank you!

I wasn't able to call the UpdateDataRow method, the using "TreeGrid.Helpers" helped me.

Regards,


MA Mohanram Anbukkarasu Syncfusion Team February 9, 2021 11:50 AM UTC

Hi Daniel, 

Thanks for the update. 

We are glad to know that the provided solution worked at your end. Please let us know if you have any further queries on this. We are happy to help you. 

Regards, 
Mohanram A. 


Loader.
Up arrow icon