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

Unable to step up in RadDateTimeEditor

3 Answers 81 Views
DateTimePicker
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 19 Oct 2011, 09:00 PM
I have a RadGrid performing some timesheet functionality with two columns StartTime and StopTime which are both GridViewDateTimeColumn. A person gets a StartTime when they clock in and a StopTime when they clock out. When the RadDateTimeEditor is initialized, I'm setting it to ShowUpDown and a custom time format since it displays time only. I'm also setting restrictions that the minValue of the StopTime equals the current value of the StartTime (since you can't clock out before you clock in). You can see the attached code for specifics. The problem is situations can occur where there is no valid StopTime. For example, if someone has a StartTime of 11:15 AM and then tries to set the StopTime, the editor will set the NullValue and MinValue of the StopTime to 11:15 AM. The step arrows for up and down show up, but clicking them does nothing since the value for both is invalid. Clicking down makes the time 10:15 AM, which is invalid and clicking up makes the time 12:15 AM which is also invalid. The numbers themselves never actually show up, but this what I assume is happening. I'm not sure what to do to fix this situation. Basically, the stepper will never work if its current value is null and the MinValue is set to anything in between 11:00 - 11:59AM. Maybe I'm missing something. Any help is appreciated.

        private void m_rgvTimesheets_CellEditorInitialized( object sender, GridViewCellEventArgs e )
        {
            if( e.ActiveEditor is RadDateTimeEditor )
            {
                var editor = (RadDateTimeEditor)(e.ActiveEditor);
                RadDateTimeEditorElement editorElement = (RadDateTimeEditorElement)editor.EditorElement;
                editorElement.ShowUpDown = true;
                editorElement.CustomFormat = "h:mm tt";
                if( e.Column.Name == ColumnTS_StopTime )
                {
                    var startTime = (DateTime) e.Row.Cells[ColumnTS_StartTime].Value;
                    editor.NullValue = startTime;
                    editor.MinValue = startTime;
                    editor.MaxValue = GetMaxTime( m_rdtpDatePicker.Value );
                }
        }
}

3 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 24 Oct 2011, 01:39 PM
Hi Jason,

Thank you for writing and for the provided code snippet.

I can confirm the undesired behavior. There are two ways to resolve this: avoid using the Editor's NullValue property or set the initial value on the Arrow Buttons click.

Please refer to the attached project which demonstrates the second solution.

I hope this helps.

All the best,
Peter
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

0
Jason
Top achievements
Rank 1
answered on 27 Oct 2011, 04:06 PM
Hi Peter,

Thanks for your reply. Not setting the null value property didn't work for me, but your second solution (handling the arrow button) worked great. Thanks!
0
Peter
Telerik team
answered on 31 Oct 2011, 10:03 AM
Hi Jason,

Thank you for writing back.

On my side if I remove the editor.NullValue line, then there is valid stop time and I can modify the value with Up/Down arrows.

var startTime = (DateTime)e.Row.Cells["StartTime"].Value;
editor.MinValue = startTime; editor.MaxValue = GetMaxTime(m_rdtpDatePicker.Value);
//editor.NullValue = startTime;

Do not hesitate to contact us if you have any further questions. All the best,
Peter
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

Tags
DateTimePicker
Asked by
Jason
Top achievements
Rank 1
Answers by
Peter
Telerik team
Jason
Top achievements
Rank 1
Share this question
or