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

SpreadsheetGrid event when a cell is recalculated?

I need to catch an event when a cell changes its value, the trick is I need to do it even if the cell "contents" are a formula that returns a value.

What can I listen for?

8 Replies

JK Jeffrey Kesselman March 6, 2016 03:46 AM UTC

Okay I found an event on SpreadsheetGrid called spreadsheet.ActiveGrid.ValueChanged 
However hooking that does not seem to generate callbacks.

Is there something else I need to do to enable it besides setting it like this:
spreadsheet.ActiveGrid.ValueChanged += ActiveGrid_ValueChanged;


KB Kanimozhi Bharathi Syncfusion Team March 7, 2016 12:39 PM UTC

Hi Jeffrey Kesselman,

Thank you for contacting Syncfusion Support.

 When the cell value is changed in Worksheet ,  you can invoke CellValueChanged Event of ActiveSheet like below code example,

spreadsheet.ActiveSheet.CellValueChanged += ActiveSheet_CellValueChanged;

void ActiveSheet_CellValueChanged(object sender, Syncfusion.XlsIO.Implementation.CellValueChangedEventArgs e)

{

    //throw new NotImplementedException();
}


Please refer the UG link to know “how to access the worksheets in the workbook”:  http://help.syncfusion.com/wpf/sfspreadsheet/working-with-sfspreadsheet#working-with-worksheet


Regards
Kanimozhi B


JK Jeffrey Kesselman March 7, 2016 03:39 PM UTC

Thank you!


KB Kanimozhi Bharathi Syncfusion Team March 8, 2016 10:10 AM UTC

Hi Jeffrey Kesselman,
We will be happy to assist you always.
Regards
Kanimozhi B


JK Jeffrey Kesselman March 8, 2016 05:25 PM UTC

Im having an issue with using this...

I have Cell F5 = "2" , cell F6 = "3"  and cell F7 = "=F5+f6"

When I change F6 = "5" I get a callback for that change in value, but I do not get a callback for F7 change its calculated value.

Is there some other event I can hook to know when calculated values change?  Or is there a way, when i know F6 has changed, to ask "what are all the cells dependent on this cell"?

Thanks

JK


KB Kanimozhi Bharathi Syncfusion Team March 9, 2016 01:10 PM UTC

Hi Jeffrey Kesselman,

Currently we do not have any event to notify the dependent cell value changes. . However you can get the list of cells dependent on the cell when the value in particular cell changes by looping the PrecedentCells of Formula Engine in CellValueChanged Event like below code example

void ActiveSheet_CellValueChanged(object sender, Syncfusion.XlsIO.Implementation.CellValueChangedEventArgs e)

{

    var grid = Spreadsheet.ActiveGrid;

    var family = FormulaEngine.GetSheetFamilyItem(grid);

    var cellref = family.GetTokenForGridModel(grid) + GridRangeInfo.GetAlphaLabel(grid.CurrentCell.ColumnIndex) + grid.CurrentCell.RowIndex;

    //To get the dependent cell

    if (grid.FormulaEngine.PrecedentCells.ContainsKey(cellref) &&

            grid.FormulaEngine.PrecedentCells[cellref] != null)

    {

        Calculatedependentcell(cellref);

        var dependentcelllist = list;   //Dependentcelllist

    }

           

}

public void Calculatedependentcell(string precedentCell)

{

    var grid = Spreadsheet.ActiveGrid;



    if (grid.FormulaEngine.PrecedentCells[precedentCell] == null) return;


    var ht = (Hashtable)((Hashtable)grid.FormulaEngine.PrecedentCells[precedentCell]).Clone();

    foreach (var o in ht.Keys)

    {

        var s1 = o as string;


        var row = grid.FormulaEngine.RowIndex(s1);

        var col = grid.FormulaEngine.ColumnIndex(s1);

        var cell = GridRangeInfo.GetAlphaLabel(col) + row;

        if (s1 != null)

        {

            list.Add(s1);

            Calculatedependentcell(s1);//recursive call            

        }

    }

}



We have also prepared a sample based on your requirement, please find the link

Sample:  http://www.syncfusion.com/downloads/support/directtrac/general/ze/sfspreadsheet_(2)1406909263

Regards
Kanimozhi B


JK Jeffrey Kesselman March 9, 2016 06:46 PM UTC

Wonderful, thank you again!


KB Kanimozhi Bharathi Syncfusion Team March 10, 2016 09:35 AM UTC

Hi Jeffrey Kesselman,

We will be happy to assist you always.

Regards
Kanimozhi B

Loader.
Live Chat Icon For mobile
Up arrow icon