Disable the GridViewDateTimeColumn TextBox

5 posts, 2 answers
  1. MikeB
    MikeB avatar
    42 posts
    Member since:
    May 2008

    Posted 03 Sep 2014 Link to this post

    Hi,

    Is there a way to set the input (TextBox) control of the GridViewDateTimeColumn to ReadOnly or Enabled = false?

    We would like to have the user select the date from the drop-down calendar only.  And not allow anything to be entered into the TextBox.

    Thanks,

    Mike
  2. Answer
    Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 04 Sep 2014 Link to this post

    Hello Michael,

    Thank you for writing.

    You can do that by accessing the date time editor in the CellEditorInitialized event, from where you can get the text box and make it read only. Here is an example:
    void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
        RadDateTimeEditor dateEditor = e.ActiveEditor as RadDateTimeEditor;
        if (dateEditor != null)
        {
            RadDateTimeEditorElement dateEditorElement = (RadDateTimeEditorElement)dateEditor.EditorElement;
            dateEditorElement.TextBoxElement.TextBoxItem.ReadOnly = true;
        }
    }

    I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.

    Regards,
    Stefan
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. MikeB
    MikeB avatar
    42 posts
    Member since:
    May 2008

    Posted 11 Sep 2014 in reply to Stefan Link to this post

    Thank you Stefan. 
    This is exactly what I needed.
    Mike
  5. MikeB
    MikeB avatar
    42 posts
    Member since:
    May 2008

    Posted 11 Sep 2014 in reply to MikeB Link to this post

    I have a follow up question.

    The Calendar Popup is only shown when the drop down arrow is clicked.

    Is there a way to display the Calendar Popup in the CellBeginEdit or CellEditorInitialized?  And of course, close when the operator clicks on a date or clicks the drop down arrow.

    Thanks again,
    Mike
  6. Answer
    Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 15 Sep 2014 Link to this post

    Hello Michael,

    Here is one way to do that:
    void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
        RadDateTimeEditor dateEditor = e.ActiveEditor as RadDateTimeEditor;
        if (dateEditor != null)
        {
            RadDateTimeEditorElement dateEditorElement = (RadDateTimeEditorElement)dateEditor.EditorElement;
            RadDateTimePickerCalendar calendarBehavior = dateEditorElement.GetCurrentBehavior() as RadDateTimePickerCalendar;
            calendarBehavior.PopupControl.PopupClosed -= PopupControl_PopupClosed; //avoids multiple subscriptions
            calendarBehavior.PopupControl.PopupClosed += PopupControl_PopupClosed;
            calendarBehavior.ShowDropDown();
        }
    }
     
    void PopupControl_PopupClosed(object sender, RadPopupClosedEventArgs args)
    {
        radGridView1.EndEdit();
    }

    I hope that the provided information addresses your question.

    Regards,
    Stefan
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top
UI for WinForms is Visual Studio 2017 Ready