This is a migrated thread and some comments may be shown as answers.

Event for cell value change - MVVM

4 Answers 181 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
Tarun
Top achievements
Rank 1
Tarun asked on 31 Jan 2014, 07:14 PM
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

4 Answers, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 03 Feb 2014, 12:04 PM
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 >>
0
Tarun
Top achievements
Rank 1
answered on 03 Feb 2014, 03:20 PM
Hi Deyan,

Is that how you would do it following MVVM? 

Regards,
Tarun
0
Tarun
Top achievements
Rank 1
answered on 04 Feb 2014, 09:49 AM
Come on, there must be some way to do this using MVVM, attached property may be, can you give me a sample please?
0
Deyan
Telerik team
answered on 04 Feb 2014, 03:49 PM
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 >>
Tags
Spreadsheet
Asked by
Tarun
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Tarun
Top achievements
Rank 1
Share this question
or