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

GridViewDateTimeColumn queries

4 Answers 183 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Johan Bjerling
Top achievements
Rank 1
Johan Bjerling asked on 14 Oct 2009, 10:49 AM
Hello,

I have a few questions regarding the GridViewDateTimeColumn.

One, is there a way to set the range of dates that you can pick? Or perhaps a way to disable future dates?

Two, is there a way to create a TimePicker column?

Three, when editing an empty DateTime column it seems I have to make a selection, if i leave the selected date as it is (i.e. todays date) that date does not "stick" when I leave the column. The only way to select todays date it seems is to select another date first (using arrow keys) then today's date or to select the date in the actual date picker. Is there a way to make today's date "stick", if you will, without having to make an explicit selection?

Thank you
Johan

4 Answers, 1 is accepted

Sort by
0
Accepted
Robert
Top achievements
Rank 1
answered on 16 Oct 2009, 05:51 PM
Hello Johan,

One:
Yes, you can do this by customizing the editor in the CellBeginEdit or CellEditorInitialized event.

RadDateTimeEditor editor = radGridView1.ActiveEditor as RadDateTimeEditor; 
editor.MinValue = DateTime.Today.AddDays(-10); 
editor.MaxValue = DateTime.Today.AddDays(10); 

Two:
You should be able to access the RadDateTimeEditorElement on the ActiveEditor and set its properties to support only times. (Do this in the CellEditorInitialized event)
RadDateTimeEditorElement element = (((RadDateTimeEditor)radGridView1.ActiveEditor).EditorElement as RadDateTimeEditorElement); 
element.Format = DateTimePickerFormat.Time; 


Three:
For this problem, I would probably set up the rows/objects in the table to have a default value of today for that field.

I hope this helps.

- Robert
0
Johan Bjerling
Top achievements
Rank 1
answered on 21 Oct 2009, 10:31 AM
Hi Robert

Thanks for your help.

Regarding point two, the solution you provided only served to change the textbox bit to timeformat.
The dropdown section still showed a calendar.
But that's ok, I can live with a dropdown with the times that I'm interested in allowing users to select.

Thank you
Johan
0
narim jacksimov
Top achievements
Rank 1
answered on 07 Dec 2009, 09:11 AM
I am actually wondering if there is a way to remove the Calendar Dropdown or change it to an updown? 

I tried setting the ShowUpDown property to true but when I do that I get a null reference exception. 
0
Jack
Telerik team
answered on 08 Dec 2009, 09:16 AM
Hello Johan,

As Narim suggested, you may set the ShowUpDown property to true. This will change the down arrow button to up/down button and will hide the calendar popup. Please consider the following code sample:

void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
{
    RadDateTimeEditor editor = this.radGridView1.ActiveEditor as RadDateTimeEditor;
    if (editor != null)
    {
        RadDateTimeEditorElement editorElement = (RadDateTimeEditorElement)editor.EditorElement;
        editorElement.ShowUpDown = true;
    }
}

Narim, please tell us whether this code works for you. If not, send us your application and I will try to locate the issue.

Another option is to use a masked textbox column. The code below shows how to setup this column to show a date:

GridViewMaskBoxColumn column = new GridViewMaskBoxColumn("maskeddate", "");
column.MaskType = MaskType.DateTime;
column.Mask = "d";
this.radGridView1.Columns.Add(column);

I hope this helps.

All the best,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Johan Bjerling
Top achievements
Rank 1
Answers by
Robert
Top achievements
Rank 1
Johan Bjerling
Top achievements
Rank 1
narim jacksimov
Top achievements
Rank 1
Jack
Telerik team
Share this question
or