Strange behavior when OldValue is set in BeforeColUpdate

Posted by: timur.kelman+c1 on 22 October 2024, 8:12 am EST

  • Posted 22 October 2024, 8:12 am EST

    In a .NET WinForms application with C1.Win.C1TrueDBGrid (4.8.20241.672) I have a trivial BeforeColUpdate event handler that just always sets the e.OldValue to “x”.

    private void c1TrueDBGrid1_BeforeColUpdate(object sender, C1.Win.C1TrueDBGrid.BeforeColUpdateEventArgs e)
    {
        e.OldValue = "x";
    }

    When I run the application and edit any cell to write any text, pressing enter (or use any other means to commit the changes) for the first time changes the text to “x”. The second time I edit text in the very same cell (showing “x” before editing), it will accept the new value I type in. The next time it’s overriden with “x” again, then isn’t, and so on.

    Is this behavior expected? Is there a way to ensure any value user typed is always overridden in the BeforeColUpdate event?

  • Posted 23 October 2024, 1:35 am EST

    Hello,

    Thanks for the steps. We’re able to observe the behavior on our end as well and escalated it to the development team for their insights. Rest assured, we’ll get back to you once we have more information.

    [Internal tracking ID: C1WIN-33188]

    However, until then, you can add an additional line in your BeforeColUpdate event to override the text every time:

    c1TrueDBGrid1[c1TrueDBGrid1.Row, c1TrueDBGrid1.Col] = "x";

    Please refer to the attached sample for the same. (see TrueDBGrid_OldValue.zip)

    Regards,

    Uttkarsh.

  • Posted 25 October 2024, 6:17 am EST

    Hello,

    As per the development team, the behavior is by design. BeforeColUpdateEventArgs.OldValue should be set to the value other than the previous value in the cell.

    You can use the following workaround for your use-case:

    private void c1TrueDBGrid1_BeforeColUpdate(object sender, C1.Win.C1TrueDBGrid.BeforeColUpdateEventArgs e)
    {
        if (e.OldValue.ToString() != "x")
            e.OldValue = "x";
        else
            c1TrueDBGrid1.DataChanged = false;
    }

    Please refer to the attached modified sample for the same. (see TrueDBGrid_OldValue_Mod.zip)

    Regards,

    Uttkarsh.

Need extra support?

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

Learn More

Forum Channels