Event for cell value change - MVVM

5 posts, 0 answers
  1. Tarun
    Tarun avatar
    6 posts
    Member since:
    Jan 2012

    Posted 31 Jan 2014 Link to this post

    Please refer to the attached screen shot, I have a scenario where I would like to update a graph based on the value change in the radSpreadsheet control. I am using MVVM, based on the sample provided by you here http://www.telerik.com/forums/spreadsheet-with-mvvm 

    Can you please advise how to capture the changed cell value in the viewmodel? 

    Thanks
    Tarun
  2. Deyan
    Admin
    Deyan avatar
    137 posts

    Posted 03 Feb 2014 Link to this post

    Hello Tarun,

    Thank you for your interest in RadSpreadsheet!

    In order to update your graph on cell value changed you may subscribe for the ActiveWorksheet's Cells CellPropertyChanged event. If you are interested only in cell value changes you may additionally use the CellPropertyChangedEventArgs and check whether the changed property name is "CellValue".

    Here follows a demo code snippet, showing how exactly you can achieve the described above:
    private const string CellValuePropertyName = "CellValue";
    private Cells cells;
     
    public MainWindow()
    {
        InitializeComponent();
     
        this.RadSpreadsheet.ActiveSheetChanged += this.RadSpreadsheet_ActiveSheetChanged;
     
        this.AttachToCellPropertyChangedEvent();
    }
     
    private void RadSpreadsheet_ActiveSheetChanged(object sender, EventArgs e)
    {
        this.DetachFromCellPropertyChangedEvent();
        this.AttachToCellPropertyChangedEvent();
    }
     
    private void AttachToCellPropertyChangedEvent()
    {
        this.cells = this.RadSpreadsheet.ActiveWorksheet.Cells;
        this.cells.CellPropertyChanged += Cells_CellPropertyChanged;
    }
     
    private void DetachFromCellPropertyChangedEvent()
    {
        if (this.cells != null)
        {
            this.cells.CellPropertyChanged -= Cells_CellPropertyChanged;
        }
    }
     
    private void Cells_CellPropertyChanged(object sender, CellPropertyChangedEventArgs e)
    {
        if (e.Property.Name == CellValuePropertyName)
        {
            System.Diagnostics.Debug.WriteLine("Cell values were changed in range: ({0})", e.CellRange);
        }
    }

    I hope this information is helpful! If you have any other questions or concerns please do not hesitate to contact us again!

    Regards,
    Deyan
    the Telerik team
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Tarun
    Tarun avatar
    6 posts
    Member since:
    Jan 2012

    Posted 03 Feb 2014 Link to this post

    Hi Deyan,

    Is that how you would do it following MVVM? 

    Regards,
    Tarun
  5. Tarun
    Tarun avatar
    6 posts
    Member since:
    Jan 2012

    Posted 04 Feb 2014 Link to this post

    Come on, there must be some way to do this using MVVM, attached property may be, can you give me a sample please?
  6. Deyan
    Admin
    Deyan avatar
    137 posts

    Posted 04 Feb 2014 Link to this post

    Hello Tarun,

    Thank you for writing back!

    RadSpreadsheet is primary designed for importing, editing and exporting spreadsheet documents. The forum thread you are referring to is MVVM example of binding the whole RadSpreadsheet's Workbook to some ViewModel. However, the control is not designed for supporting cell values binding MVVM scenarios.

    In the concrete case you have described you may create your own ViewModel used for the needed bindings and internally this ViewModel should rely on the earlier proposed CellPropertyChanged event.

    Let me know if you have further questions!

    Regards,
    Deyan
    the Telerik team
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
UI for WPF is Visual Studio 2017 Ready