[NET6] C1FlexGrid and IEmbeddedEditor with C1DateEdit

Posted by: wknauf on 1 March 2023, 8:36 pm EST

  • Posted 1 March 2023, 8:36 pm EST

    Hi C1,

    attached solution contains two samples for .NET6 and .NET48: a C1.Win.Calendar.C1DateEdit is placed on a UserControl, which is used as C1FlexGrid column editor by implementing “IEmbeddedEditor” (.NET6) or “IC1EmbeddedEditor” (.NET 4.8).

    FlexValidate.zip

    In the .NET6 version, the control value is not applied to the grid cell: click in the cell, change the value by typing a new date, then click outside of the editor.

    In .NET 4.8, it works fine.

    It seems to be a problem of my code in “GetValue”: here I return “C1DateEdit.Value”, which does not contain the new value.

    I could workaround this problem by triggering validation in “IEmbeddedEditor.IsValueValid”:

        public bool IsValueValid()
        {
          //Force validation of the C1DateEdit:
          return this.Validate();
        }

    By the way: I also added PostValidation code to cancel on invalid values, and this is triggered even without my workaround. So the problem is only that the value is not applied to the “Value” picker.

    What do you think? Is this a bug in the control? Or is my workaround necessary in the .NET6 version? Is there even a better workaround?

    Best regards

    Wolfgang

  • Posted 1 March 2023, 10:01 pm EST

    Just an update: The workaround to call “Validate” does not work always. The control behaves differently when using TAB to leave the editor or when clicking outside of it.

    It works best when calling “C1DateEdit.UpdateValueWithCurrentText”

  • Posted 6 March 2023, 2:35 pm EST - Updated 6 March 2023, 2:44 pm EST

    Hi Wolfgang,

    Apologies for the delay in response.

    We could observe the behavior you have mentioned at our end. As per our investigation, it seems the PostValidating event of C1DateEdit in NET6 is called after the FlexGrid calls the GetValue method to get the value from the editor. We have escalated the issue to the development team. We will update you as soon as we have any updates.

    [TrackingID : [C1WIN-29240]]

    In the meantime, as a workaround, you can use the UpdateValueWithCurrentText method in the IsValueValid(), since the grid calls IsValueValid() before the GetValue(), the value will be updated before it is fetched by the grid.

    Regards

    Avnish

  • Posted 24 April 2023, 6:18 pm EST

    Hi,

    As per the development team, this is not a bug but an issue with the implementation. The DateEdit in .NET 6 is a different control than is .NET FW 452 (just like the other C1Input controls). And in this case behaves a little differently. C1DateEdit already implements IEmbeddedEditor interface and has no such issue.

    The team has suggested that it would be better if you inherit from DateEdit instead of using it in a UserControl. If you still want to use it in a UserControl then you should call the c1DateEdit1.Initialize in MyDateEdit.Initialize method:

    public void Initialize(object value, IDictionary attrs)
    {
       if (attrs.Contains("Format"))
          attrs.Remove("Format");
       c1DateEdit1.Initialize(value, attrs);
       //...
    }
    

    This will inform the C1DateEdit that it should behave like an embedded editor and there will be no issue. If you face any issues, do let us know.

    Regards.

  • Posted 25 April 2023, 5:19 pm EST

    Hi Avnish,

    due to implementation details, I have to stick with the UserControl approach.

    The suggested code does not seem to work - I added the code snippet to “MyDateEdit.Initialize”, but without the call to “UpdateValueWithCurrentText” in “IsValueValid”, the value of C1DateEdit is not written to the cell.

    Could you update my initial sample with the suggested code? Maybe I misunderstood you.

    Best regards

    Wolfgang

  • Posted 25 April 2023, 5:37 pm EST

    Hi Wolfgang,

    Apologies, i missed that. You would also need to call the IsValueValid of the C1DateEdit. You can also do the same for GetValue. Please refer to the sample attached.

    public bool IsValueValid()
            {
                return (c1DateEdit1 as IEmbeddedEditor).IsValueValid();
            }

    Regards

    AvnishFlexValidate_mod.zip

  • Posted 25 April 2023, 6:49 pm EST

    Thanks!

    Seems that only the call to “C1DateEdit.IsValueValid” is necessary in my sample, and this method internally also calls “UpdateValueWithCurrentText”.

    The other changes in “Initialize” and “GetValue” do not seem to be required for our code.

    Best regards

    Wolfgang

Need extra support?

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

Learn More

Forum Channels