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

Disable the GridViewDateTimeColumn TextBox

4 Answers 79 Views
GridView
This is a migrated thread and some comments may be shown as answers.
MikeB
Top achievements
Rank 1
MikeB asked on 03 Sep 2014, 07:49 PM
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

4 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 04 Sep 2014, 07:37 AM
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.
 
0
MikeB
Top achievements
Rank 1
answered on 11 Sep 2014, 05:05 PM
Thank you Stefan. 
This is exactly what I needed.
Mike
0
MikeB
Top achievements
Rank 1
answered on 11 Sep 2014, 10:08 PM
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
0
Accepted
Stefan
Telerik team
answered on 15 Sep 2014, 08:06 AM
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.
 
Tags
GridView
Asked by
MikeB
Top achievements
Rank 1
Answers by
Stefan
Telerik team
MikeB
Top achievements
Rank 1
Share this question
or