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

GridTimePickerEditor

6 Answers 74 Views
GridView
This is a migrated thread and some comments may be shown as answers.
pierre-jean
Top achievements
Rank 1
Veteran
Iron
pierre-jean asked on 17 Oct 2017, 02:44 PM

I have a databound gridview with a column containing time a time value and I have inserted the below code to allow editing the time in the cell

1. The editing works fine, but when I enter the cell the displayed value is {0:09:45} is this normal ? is it possible to change it to 09:45 ?

2. is it possible to modify the column width when it enters in edit mode otherwise the timepicker editor is shrunk

3. How do I change the TimeEditor to display times in 24hrs instead of AM/PM ?

Thanks 

 

    Private Sub gvShow_EditorRequired(sender As Object, e As EditorRequiredEventArgs) Handles gvShow.EditorRequired
        If gvShow.CurrentColumn.Name = "StartTime" Then e.Editor = New GridTimePickerEditor
    End Sub

6 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 20 Oct 2017, 06:04 AM
Hello, Pierre-Jean,  

Thank you for writing.  

Please refer to the following code snippet demonstrating how to specify the time format for the grid cells and the editor. The result is illustrated in the attached screenshot:
Sub New()
 
    InitializeComponent()
 
    Dim dateTimeColumn As New GridViewDateTimeColumn("DateTimeColumn")
    dateTimeColumn.FormatString = "{0:HH:mm}" ' format for the cells
    dateTimeColumn.Format = DateTimePickerFormat.Custom
    dateTimeColumn.CustomFormat = "HH:mm"
    Me.RadGridView1.Columns.Add(dateTimeColumn)
    Me.RadGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill
 
    For index = 1 To 10
        Me.RadGridView1.Rows.Add(DateTime.Now.AddHours(index).AddMinutes(index))
    Next
 
    AddHandler Me.RadGridView1.EditorRequired, AddressOf EditorRequired
End Sub
 
Private Sub EditorRequired(sender As Object, e As EditorRequiredEventArgs)
    If Me.RadGridView1.CurrentColumn.Name = "DateTimeColumn" Then e.Editor = New GridTimePickerEditor
End Sub

Additional information for the GridViewDateTimeColumn is available here: https://docs.telerik.com/devtools/winforms/gridview/columns/column-types/gridviewdatetimecolumn

I hope this information helps. Should you have further questions I would be glad to help.

Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
pierre-jean
Top achievements
Rank 1
Veteran
Iron
answered on 20 Oct 2017, 10:08 AM

Thank you for your message, but I have not been able to make it work.

the difference might be in the fact that I have a databound grid and the column data comes from the table.

I have added the follwing code

        InitializeComponent()
        ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
        AddHandler gvShow.EditorRequired, AddressOf EditorRequired

'CALLED after databinding
            Dim TimeCol As New GridViewDateTimeColumn
            TimeCol = gvShow.MasterTemplate.Columns("StartTime")
            TimeCol.FormatString = "{0:HH:mm}"
            TimeCol.Format = DateTimePickerFormat.Custom
            TimeCol.CustomFormat = "HH:mm"
            TimeCol.AutoSizeMode = GridViewAutoSizeColumnsMode.Fill
.....

    Private Sub EditorRequired(sender As Object, e As EditorRequiredEventArgs) Handles gvShow.EditorRequired
        If gvShow.Tag = "CO" And gvShow.CurrentColumn.Name = "StartTime" Then e.Editor = New GridTimePickerEditor
    End Sub

and:

1. The column does displays in time correct format (see screenShot1)

2. but When I clic on the "clock" the time displayed is not in "HH:mm" (24hrs) format and the column width is too small (See Screen Shot 2)

 

0
pierre-jean
Top achievements
Rank 1
Veteran
Iron
answered on 20 Oct 2017, 12:15 PM

Just a few additional information:

1. I have tried to set the culture info to "fr-FR" which, displays time in 24hr formats -> No Change

2. In de detail pane of my object I use the datetimepicker control and I get the correct behavior (see ScreenShot3)

Thanks in advance

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 Oct 2017, 09:45 AM
Hello, Pierre-Jean,    

Thank you for writing back. 

Depending on the applied culture to the RadTimePickerElement the hours in the drop down are filled. If AMDesignator/PMDesignator are not empty in the culture, the AM/PM section is shown in the popup. Please refer to the attached sample project which result is illustrated in the attached screenshot.

I hope this information helps. If you have any additional questions, please let me know. 

 Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
pierre-jean
Top achievements
Rank 1
Veteran
Iron
answered on 23 Oct 2017, 04:40 PM

Thanks a lot

I had thought that the culture info would be passed from the form to the control and to the editor, but it works with your information.

Thanks a lot

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Oct 2017, 11:03 AM
Hello,  Pierre-Jean,    

Thank you for writing back. 

Indeed, you can specify the culture for the entire application by using the code snippet below. Thus, the time picker in the editor will consider it when populating the hours' table: 
Dim culture As New System.Globalization.CultureInfo("en-GB")
culture.DateTimeFormat.AMDesignator = ""
culture.DateTimeFormat.PMDesignator = ""
System.Threading.Thread.CurrentThread.CurrentCulture = culture

I hope this information helps. If you have any additional questions, please let me know. 

 Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
pierre-jean
Top achievements
Rank 1
Veteran
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
pierre-jean
Top achievements
Rank 1
Veteran
Iron
Share this question
or