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

DateTime? display as Textbox

3 Answers 90 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Markus
Top achievements
Rank 1
Markus asked on 26 Feb 2009, 09:36 AM
Hi,

nullable datetime columns ( DateTime ? ) are displayed as textbox in the grid. When I change the column to normal DateTime it displays as a datepicker. Is this expected behaviour? How can I display nullable datetimes as datepicker?

Thanks in advance
Best regards
Markus

3 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 26 Feb 2009, 10:00 AM
Hi Markus,

Currently the GridViewDateTimeColumn does not support nullable types. We plan to add this functionality in one of our upcoming releases.

You could use the CellFormatting event to customize the cell value when it is null. Here is a sample:

void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e) 
    if (e.CellElement is GridDateTimeCellElement) 
    { 
        GridDateTimeCellElement cell = (GridDateTimeCellElement)e.CellElement; 
        if (cell.Value == null || cell.Value == System.DBNull.Value) 
        { 
            cell.Text = "null"
        } 
    } 


I hope this helps. Should you have any further questions, please do not hesitate to ask.

Greetings,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Markus
Top achievements
Rank 1
answered on 26 Feb 2009, 11:02 AM
Hi Jack,

thanks for your answer. The CellFormatting event will work if the db-column is allready null, but what if the user wants to enter the null value? The datepicker seems to have no option to set the date to null.
Because we are using OpenAccess Express there is furthermore a problem with the forward-mapping. If we map the DateTime? (nullable) the db table is created as nullable whereas the "normal" DateTime is mapped with the not null constraint.

Best Regards
Markus


0
Jack
Telerik team
answered on 27 Feb 2009, 10:41 AM
Hello Markus,

An option is to customize the context menu for the date time cells. You should handle the ContextMenuOpening event in this case.

Consider the following code snippet:

void radGridView1_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e) 
    if (e.ContextMenuProvider is GridDateTimeCellElement) 
    { 
        RadMenuItem item = new RadMenuItem("Clear date", e.ContextMenuProvider); 
        item.Click += new EventHandler(item_Click); 
        e.ContextMenu.Items.Add(item); 
    } 
 
void item_Click(object sender, EventArgs e) 
    RadMenuItem menuItem = (RadMenuItem)sender;; 
    GridDateTimeCellElement cell = (GridDateTimeCellElement)menuItem.Tag; 
    cell.Value = null
    this.radGridView1.GridElement.Update(GridUINotifyAction.StateChanged); 

I hope this helps. If you need further assistance, please write me.

Kind regards,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Markus
Top achievements
Rank 1
Answers by
Jack
Telerik team
Markus
Top achievements
Rank 1
Share this question
or