C1DatePicker in DataTemlate C1DataGrid cannot getvalue from C1MaskTextBox

Posted by: mr.wlight on 25 June 2018, 3:38 pm EST

    • Post Options:
    • Link

    Posted 25 June 2018, 3:38 pm EST

    Hi,

    I have a trouble with C1DatePicker in CellEditTemplate. My project have a Label to display date in CellTemplate and C1DatePicker to set value to it.

    No problem with Popup in C1DatePicker, but when i input date in C1MaskTextBox then i click to another cell or row or anything, this value can’t not set to C1DatePicker

    And with default Datagrid, everything is ok.

    Is this a bug? And can u help me fix it?

  • Posted 25 June 2018, 3:44 pm EST

    This’s my demo project . And i can’t attach file below @@.

    https://drive.google.com/file/d/1bwMHqVOxPo9SXGPw_-7PCGUhhSGiqSmY/view?usp=sharing

  • Posted 27 June 2018, 12:13 am EST

    Hi,

    Thank you for the application.

    However, I am having a little trouble with matching the sample and your requirement. So, to confirm, do you mean that when Label is replaced with C1MaskedTextBox in CellTemplate, then C1DatePicker of CellEditingTemplate does not pick the date entered in C1MaskedTextBox? If that is the case, then I tried the same with DataGrid and the behavior is same for both.

    So, could you please confirm whether our understanding is correct/wrong or is there anything that we’re missing here.

    Thanks,

    Ruchir

  • Posted 27 June 2018, 6:42 pm EST

    Sorry for my bad English. Because i’m have behavior with Enter key, when i press enter, the current row will change to next row.

    You can see my problem in my picture below

  • Posted 28 June 2018, 5:40 pm EST

    Hi,

    Thank you for elaborating further and for sharing the images.

    This is because C1DatePicker inside uses C1MaskedTextBox. To resolve this issue, you need to handle C1Datagrid’s CommittingEdit event and pass the entered value there, as follows:

    private void datagrid_CommittingEdit(object sender, C1.WPF.DataGrid.DataGridEndingEditEventArgs e)
            {
                if (e.Column.Index == 0)
                {
                    var bdr = e.EditingElement as Border;
                    if (bdr != null)
                    {
                        var dp = bdr.Child as C1DatePicker;
                        if (dp != null)
                        {
                            dp.CustomFormat = "M/d/yyyy";
                            var tb = FindChild<C1.WPF.C1MaskedTextBox>(dp, "TextBox");
                            if (tb != null)
                            {
                                var val = tb.Value;
                                try
                                {
                                    var date = Convert.ToDateTime(val);
                                    dp.SelectedDate = date;
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show("The text entered is not a valid date");
                                }
                            }
                        }
                    }
                }
            }
    ```Also attached is modified sample application for your reference.
    
    Thanks,
    Ruchir[zip filename="C1DatePickerWithC1DataGrid_fixed.zip"]https://gccontent.blob.core.windows.net/forum-uploads/file-788aac7c-6435-4e8c-a054-74bfbdad21ee.zip[/zip]
  • Posted 1 July 2018, 11:02 pm EST

    Hi Ruchir.Agarwal,

    Tks for your support!

Need extra support?

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

Learn More

Forum Channels