c1Datagrid DataGridDateTimeColumn input behavior difference

Posted by: sebastian-jn.k on 17 December 2021, 3:32 am EST

    • Post Options:
    • Link

    Posted 17 December 2021, 3:32 am EST

    assembly name C1.WPF.DataGrid.4.5.2 version 4.5.20212.747

    c1Datagrid c1:DataGridDateTimeColumn keyboard input behavior difference to c1:DataGridTextColumn

    workflow with DataGridTextColumn:

    -one click on Textcolumn

    -typing the character ‘2’

    result:

    the character ‘2’ is immediately inserted

    workflow with DataGridDateTimeColumn:

    -one click on DataGridDateTimeColumn

    -typing the character ‘2’

    result:

    the character ‘2’ is NOT inserted only the edit mode started.

    problem:

    i have to type the 2 again.

    question:

    how do i achieve the same behavior like DataGridTextColumn with the DataGridDateTimeColumn ?

    i tried:

    -catch event previewtextinput on cell

    -start cell edit mode to get the edit controls

    -resend the previewtextinput character to the C1MaskedTextBox (child?) from the c1DateTimePicker

    -but i cannot find the C1MaskedTextBox in the visual tree.

    sample project attachted

    private void DataGridCellPresenter_PreviewTextInput(object sender, TextCompositionEventArgs e)

    {

    var dgcp = sender as DataGridCellPresenter;

    if(dgcp.Cell.Column is DataGridDateTimeColumn)

    {

    if (!dgcp.Cell.IsEditing)

    {

    dgcp.DataGrid.BeginEdit(dgcp.Cell);

    var editCellPresenter = dgcp.DataGrid.CurrentCell.Presenter as FrameworkElement;

    var mtb = FindChild<C1.WPF.C1MaskedTextBox>(editCellPresenter);

    //problem here: C1MaskedTextBox is null

    if (mtb != null)

    {

    TextCompositionManager.StartComposition(new TextComposition(InputManager.Current, mtb, e.Text));

    }

    }

    }

    }

    greetings from germany

  • Posted 17 December 2021, 6:07 am EST

  • Posted 20 December 2021, 3:47 am EST

    Hello,

    Thanks for the sample.

    In your case, C1MaskedTextBox is null because C1DateTimePicker isn’t loaded yet. In order to achieve your requirement, you need to wait until C1DateTimePicker load. (see code snippet)

    
    private  async void DataGridCellPresenter_PreviewTextInput(object sender, TextCompositionEventArgs e)
            {
                var dgcp = sender as DataGridCellPresenter;
                if(dgcp.Cell.Column is DataGridDateTimeColumn) 
                {
                    if (!dgcp.Cell.IsEditing)
                    {
                        dgcp.DataGrid.BeginEdit(dgcp.Cell);
                        var editCellPresenter = dgcp.DataGrid.CurrentCell.Presenter as FrameworkElement;
                        await Task.Delay(200);
                        var mtb = FindChild<C1.WPF.C1MaskedTextBox>(editCellPresenter);
                        if (mtb != null)
                        {
                            TextCompositionManager.StartComposition(new TextComposition(InputManager.Current, mtb, e.Text));
                        }
                    }
                }
            }
    
    

    Please refer the attached modified sample for he same : C1DatagridDateTimeProblems_Mod.zip

    Best Regards,

    Nitin

Need extra support?

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

Learn More

Forum Channels