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

Adding/Editing timestamp column in the grid

6 Answers 75 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 25 Jun 2012, 04:04 PM
I have a scenario where one column in the table is a timestamp (date + time). I have my grid column configured as follows:

<telerik:GridViewDataColumn
        UniqueName="Timestamp"
        DataMemberBinding="{Binding Timestamp}"
        Header="Timestamp"
        DataFormatString="{} {0:MM/dd/yyyy HH:mm:ss}"
        IsFilterable="False" />

The property is coded as:
public DateTime? Timestamp
{
    get
    {
        ... returns either NULL or datetime object
    }
    set
    {
        _timestamp = value;
    }
}

The display part is working fine: an example of the value displayed is:  12/20/2020 18:40:00

The problem I have is when adding a new row or editing an existing row. When adding a new row, the grid displays an empty row, and if I type in "12/20/2020 18:40:00" and tab out of the column to go to the next column, the timestamp column value is set to NULL (when putting a breakpoint on setter) and the timestamp I entered is wiped out. If I just type the date part (12/20/2020) and tab out, things work fine: the value is set correctly and the column displays "12/20/2020 00:00:00".  I observe similar behavior when trying to edit a row. Do I need to specify a mask, a converter, or something else to get the column to properly accept the timestamp?

Thanks

Andrey

6 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 25 Jun 2012, 04:13 PM
Hello Eric ,

Indeed the first thing you may try is to use a diagnostic converter . You can set one for the DataMemberBinding.
Then in the convert method you can easily check whether the string input can be correctly parsed t a valid DateTime.

Let me know in case it does not help.

All the best,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Eric
Top achievements
Rank 1
answered on 25 Jun 2012, 04:36 PM
Hi, I assume you mean creating a diagnostics converter, something like the following: 

public class DiagnosticsConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return value;
    }
 
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return value;
    }
}

I did that, and when I tab off the field, the value that is passed to the Convert method is NULL.

EDIT: Now that I think about it, I am surprised the debugger stopped in the Convert method and not in the ConvertBack after I entered a new value into the new row's cell.
0
Eric
Top achievements
Rank 1
answered on 26 Jun 2012, 07:18 PM
Pavel,
is there any chance you can take a look at my problem. I really need this resolved.

Thanks
0
Eric
Top achievements
Rank 1
answered on 27 Jun 2012, 08:10 PM
I solved my own problem. Here is the link to the topic that helped:  http://www.telerik.com/community/forums/wpf/gridview/can-t-set-time-portion-for-datetime-picker-column.aspx 

To be honest I don't understand why this functionality is not working out of the box (and why Telerik team is not responding to my problem since the initial suggestion that did not work)
0
Pavel Pavlov
Telerik team
answered on 28 Jun 2012, 11:47 AM
Hi Eric ,

I 'm glad to read  you have solved the problem . Please excuse us for the delay. Sometimes without having the project by our side is takes some more time for investigation and proper suggestion.

In case you need further help you are always welcome to open a support ticket (instead a forum post).

Although forums are frequently monitored , support tickets will ensure a timely answer (according to your license ) and will give you the ability to attach a project which we can debug at our side.

Regards,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Eric
Top achievements
Rank 1
answered on 03 Jul 2012, 01:41 PM
Pavel,
thanks for the response. I will create a sample project next time
Tags
GridView
Asked by
Eric
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Eric
Top achievements
Rank 1
Share this question
or