Capture the previous value on cell changed

Posted by: alex.corti on 6 February 2024, 8:03 pm EST

  • Posted 6 February 2024, 8:03 pm EST

    Good morning,

    I have a grid and when I leave the cell after the change, I set the text as Red and I enable a save button.

    Now I disable the cell where the content is Primary Key (PK) on the table of DB.

    So I update all the cells except PK.

    I need your help to allow the final user to edit PK to.

    So I have to save previous PK. to make

    UPDATE table_name set Pk_col = ‘NEW_VALUE’ where PK_col = ‘OLD_VALUE’

    There is a way in _CellChanged event to capture the OLD_VALUE?

    Thanks Alex

    This is my portion of code where (i think) i have to capture the OLD_VALUE.

    private void _fgTable_CellChanged(object sender, RowColEventArgs e)

    {

    try

    {

    if (_isLoading) return;

    CellStyle s = _fgTable.Styles.Add(“IsChanged”);

    s.ForeColor = Color.Red;

    CellRange rg = _fgTable.GetCellRange(e.Row, e.Col);

    rg.Style = _fgTable.Styles[“IsChanged”];

    enableButtons(true);

    _modifyInProgress = true;

    }

    catch (Exception ex)

    {

        ctrlLogger.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        ctrlLogger.Error(ex.Message + "\n" + ex.StackTrace);
        if (ex.InnerException != null)
            ctrlLogger.Error("Inner Exception: " + ex.InnerException.Message);
    }
    

    }

  • Posted 6 February 2024, 9:12 pm EST

    Hi Alex,

    you have to store the original value yourself, no chance to access it in “CellChanged” event. The easiest way to achieve this is to set it to the row or cell user data.

    E.g.:

    _fgTable.Rows[x].UserData = myOriginalPK;

    or

    _fgTable.SetUserData(row, col, myOriginalPK);

    You can fetch this user data in “CellChanged”.

    Hope this helps

    Wolfgang

  • Posted 7 February 2024, 1:23 am EST

    Hi Wolfgang,

    i will test it and I will give a feedback.

    Thanks for the moment

  • Posted 7 February 2024, 9:56 pm EST

    Hello Alex,

    Thank you, Wolfgang, for your input here.

    Alex, as Wolfgang said, it is not possible to get old cell values in the CellChanged event. You can store old cell values and access them in the CellChanged event.

    We have created a simple sample to show-case the same. Please refer to the attached sample, FlexGrid_GetOldValue.zip.

    You can also use the ValidateEdit event, as you can access both old and new cell values. Please refer to ValidateEdit in the documentation.

    see: https://developer.mescius.com/componentone/docs/win/online-flexgrid/edit-mode.html

    Regards,

    Uttkarsh.

  • Posted 9 February 2024, 1:22 am EST

    Thanks the task is solved with your help.

    Alex

  • Posted 11 February 2024, 3:31 pm EST

    Hello Alex,

    We are glad to know that your task has been resolved.

    If you require any further assistance or have any questions, please do not hesitate to reach out to us.

    Regards,

    Uttkarsh.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels