Force refreshing of Radspreadsheet control from code-behind in WPF

1 Answer 60 Views
Spreadsheet
Laurent
Top achievements
Rank 1
Iron
Laurent asked on 06 Sep 2023, 03:28 PM

Hi, 

I am using the RadSpreadsheet user control in WPF.

I am using 2 instances of this control in 2 different windows, with the same underlying Workbook such that modifications to the workbook in one control should be propagated to the other one. The idea is that one control offers a small preview of the workbook, while the second one is used in a separate window with extra-ribbon, formula bar... for more confortable editing (i.e enlarged view).

The problem is that changes from one spreadsheet control are not automatically reflected in the other "untouched" spreadsheet control. Changes are only reflected once I play with the display of the "untouched" spreadsheet control, such as changing the zoom level (via the status bar control) or clicking to change the current active sheet back and forth.

I was wondering if there is a function to force refreshing the radspreadsheet control so the display matches the underlying workbook.

I dont need to have the changes being reflected in real time, it would be enough to use such function to refresh the control used for preview once the larger window with the second control is closing.

Thanks

1 Answer, 1 is accepted

Sort by
0
Laurent
Top achievements
Rank 1
Iron
answered on 07 Sep 2023, 09:42 AM

Well after inspecting the decompiled source code for RadSpreadsheet, it turns out the private method UpdateActiveSheetEditor is the one I was looking for.

I accessed it using reflection, I also made a custom UserControl extending RadSpreadsheet that exposes the method, in case I would need it more often.

Could the method be made public or protected in later releases maybe ?

public class CustomSpreadsheet : RadSpreadsheet
{

    /// <summary>
    /// A reference to the private method UpdateActiveSheetEditor from Radspreadsheet, needed to force refreshing the spreadsheet. <br/>
    /// Made available by a hack using reflection.
    /// </summary>
    private MethodInfo _updateActiveSheetMethod;

    CustomSpreadsheet() {

        // Use reflection to make the UpdateActiveSheetEditor accessible
        // The method is private within the RadSpreadsheet class, using this.GetType() would not work as the method is not visible to a derived class such as CustomSpreadsheet
        _updateActiveSheetMethod = typeof(RadSpreadsheet).GetMethod("UpdateActiveSheetEditor", BindingFlags.Instance | BindingFlags.NonPublic);
    }

    /// <summary>
    /// Force the current sheet to refresh it's view to match the current data in the backend.
    /// </summary>
    public void RefreshActiveSheet()
    {
        if (_updateActiveSheetMethod == null)
            LoggingController.Instance.LogError("Could not resolve method UpdateActiveSheetEditor");
        
        else
        // Make an invocation:
            _updateActiveSheetMethod.Invoke(this, null);

    }

}    

Tags
Spreadsheet
Asked by
Laurent
Top achievements
Rank 1
Iron
Answers by
Laurent
Top achievements
Rank 1
Iron
Share this question
or