This is a migrated thread and some comments may be shown as answers.

Custom DatePicker column UI update

2 Answers 25 Views
GridView
This is a migrated thread and some comments may be shown as answers.
SPE
Top achievements
Rank 1
SPE asked on 16 Nov 2011, 06:34 AM

Hi,

First of all, I'm sorry that my English is absurd.


I made a custom datepicker column.

If I type 'enter' when I want to finish editing the column,

it changes the value of its DataContext well, and the it updates the UI, too.


However, if I just click another cell or other UI element when editing is finished, (when the cell losts its focus)

It changes the value of its DataContext, but not the UI.

So the UI shows past value of the DataContext.

And when I click the cell again, the UI is updated.



I found that telerik's default date column works well.

But not mine... So It makes me sad.


Since I can't attach my solution in this forum,

I copied my source code.



    public class SpeDateColumn : GridViewBoundColumnBase
    {
        public override FrameworkElement CreateCellEditElement(GridViewCell cell, object dataItem)
        {
            this.BindingTarget = RadDatePicker.SelectedDateProperty;
            var picker = new RadDatePicker();
            picker.SetBinding(this.BindingTarget, this.CreateValueBinding());

            return picker;
        }

        private Binding CreateValueBinding()
        {
            var valueBinding = new Binding();
            valueBinding.Mode = BindingMode.TwoWay;
            valueBinding.UpdateSourceTrigger = UpdateSourceTrigger.Default;
            valueBinding.Path = new PropertyPath(this.DataMemberBinding.Path.Path);
            return valueBinding;
        }
    }





Thank you in advance.

2 Answers, 1 is accepted

Sort by
0
Accepted
Nedyalko Nikolov
Telerik team
answered on 21 Nov 2011, 08:41 AM
Hello Sunmin,

This is a known issue with RadDateTimePicker which fortunately can be solved with a few lines of code.
Just override GetNewValueFromEditor() method with the following one:

public override object GetNewValueFromEditor(object editor)
        {
            var picker = editor as RadDateTimePicker;
            if (picker != null)
            {
                picker.DateTimeText = picker.CurrentDateTimeText;
            }
            return base.GetNewValueFromEditor(editor);
        }

Let me know if this does not help.

Best wishes,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
SPE
Top achievements
Rank 1
answered on 22 Nov 2011, 01:12 AM

Very thank you, Nedyalko Nikolov!

I resolved my problem, and it may not be possible without your help.

Have a nice day.

Tags
GridView
Asked by
SPE
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
SPE
Top achievements
Rank 1
Share this question
or