Show the datetimepicker in dropped down mode when a gridview cell is selected

2 posts, 0 answers
  1. Terry
    Terry avatar
    6 posts
    Member since:
    Nov 2011

    Posted 20 Jun 2012 Link to this post

    I have a RadGridView in Winforms and a date time cell which when clicked will show the text edit mode and a drop down arrow to the right. On clicking the drop down arrow the nice calendar date picker shows.

    I'm trying to get the calendar to show straight away but can't find a method on the calendar object. My current code is as follows;

    Private Sub OrderGridView_CellEditorInitialized(sender As Object, e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles OrderGridView.CellEditorInitialized
        Console.WriteLine("Editor init: {0}", e.ToString())
     
        Dim editor = TryCast(OrderGridView.ActiveEditor, RadDateTimeEditor)
        If (editor IsNot Nothing) Then
            Dim calendar = DirectCast(editor.EditorElement, RadDateTimeEditorElement)
            calendar.GetCurrentBehavior().DateTimePickerElement.Visibility = Telerik.WinControls.ElementVisibility.Visible
            calendar.PerformClick()
            calendar.Select()
        End If
     
    End Sub


    Is there a way to do this? Perhaps if not possible, I'll fake a click to the drop down button.

    Thanks in advance
  2. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 25 Jun 2012 Link to this post

    Hello Terry,

    Thank you for contacting Telerik support.

    You should call ShowPopup method in order to show the calendar portion of the DateTimePicker Editor.
    Please refer to code below and to the sample project.
    Private Sub OrderGridView_CellEditorInitialized(sender As Object, e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles OrderGridView.CellEditorInitialized
     
        Console.WriteLine("Editor init: {0}", e.ToString())
     
        Dim editor = TryCast(OrderGridView.ActiveEditor, RadDateTimeEditor)
     
        If (editor IsNot Nothing) Then
     
            Dim calendar = DirectCast(editor.EditorElement, RadDateTimeEditorElement)
     
            TryCast(calendar.GetCurrentBehavior(), RadDateTimePickerCalendar).Calendar.LoadElementTree()
     
            AddHandler TryCast(calendar.GetCurrentBehavior(), RadDateTimePickerCalendar).PopupControl.PopupClosing, AddressOf canClose
     
            TryCast(calendar.GetCurrentBehavior(), RadDateTimePickerCalendar).ShowDropDown()
     
        End If
    End Sub
     
    Private Sub canClose(sender As Object, args As RadPopupClosingEventArgs)
        args.Cancel = args.CloseReason = RadPopupCloseReason.AppFocusChange
    End Sub

    I hope this helps.

    All the best,
    Peter
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top