Editing Time in a Grid

5 posts, 0 answers
  1. Terry
    Terry avatar
    157 posts
    Member since:
    Jul 2009

    Posted 18 Mar 2010 Link to this post

    Hi:

    I want to edit a time (from a bound datetime column) in a RadGridView.

    I've defined the grid column as follows:

                    <radGridView:GridViewDataColumn Header="End Time" 
                            DataMemberBinding="{Binding EndTime, Mode=TwoWay}" DataFormatString="{}{0:hh:mm tt}">  
                        <radGridView:GridViewDataColumn.CellTemplate> 
                            <DataTemplate> 
                                <TextBlock Text="{Binding EndTime}" /> 
                            </DataTemplate> 
                        </radGridView:GridViewDataColumn.CellTemplate> 
                        <radGridView:GridViewDataColumn.CellEditTemplate> 
                            <DataTemplate> 
                                <radInput:RadTimePicker  
                                     SelectedTime="{Binding EndTime, Mode=TwoWay}" /> 
                            </DataTemplate> 
                        </radGridView:GridViewDataColumn.CellEditTemplate> 
                    </radGridView:GridViewDataColumn> 
     

    I have two problems:
    1. The time displays in the TextBlock as mm/dd/yy hh:mm tt.  How can I format the TextBlock to just show the time?  BTW, the following does not work.  It leaves the time blank.  (THe VS2010 syntax coloring has the zero black, the hh brown, the mm blue and the tt red.)

              <TextBlock Text="{Binding EndTime, StringFormat='{}{0:hh:mm tt}'}" /> 
     


    2. When I double-click the cell to edit it, the time in the timepicker is blank rather than showing the underlying time which is being edited.  Shouldn't SelectedTime make it show the same time as I saw in the TextBlock?

    I'm using SL4 beta.
  2. Surya
    Surya avatar
    2 posts
    Member since:
    Mar 2008

    Posted 20 Mar 2010 Link to this post

    Hi,

    I have the same issue. I am using VS 2010 RC with SL4 RC. I have defined the grid column as follows.

    <telerikGridView:GridViewDataColumn Header="Start Time"  
        DataMemberBinding="{Binding StartTime, Mode=TwoWay}" 
        DataFormatString="{}{0:t}"
        <telerikGridView:GridViewDataColumn.CellEditTemplate> 
            <DataTemplate> 
                <telerikInput:RadTimePicker Loaded="Editor_Loaded" 
                    SelectedTime="{Binding StartTime, Mode=TwoWay}" /> 
            </DataTemplate> 
        </telerikGridView:GridViewDataColumn.CellEditTemplate> 
    </telerikGridView:GridViewDataColumn> 
     

    Please advice.
  3. DevCraft banner
  4. Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 24 Mar 2010 Link to this post

    Hi Surya,

    There are some ways to overcome this issue. You can build a ValueConverter that will transform the date to the desire value.  Also you can try to specified the FormatString in the TextBlock binding expression. You should know that the SelectedTime property of the RadTimePicker is of TimeSpan type, not a DateTime object. Let us know if this solutions are not helping you.

    Regards,
    Kaloyan
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. Terry
    Terry avatar
    157 posts
    Member since:
    Jul 2009

    Posted 24 Mar 2010 Link to this post

    I've experimented.  If you are retrieving a SQL Time Column from SQL Server, the type is TimeSpan and the TimePicker selected value initializes correctly.  It successfully initializes to {}{0:hh:mm tt} when you enter edit mode.  But then the problem is, when you're not in edit mode, the TextBlock formatting doesn't understand {}{0:hh:mm tt} and leaves the column blank.  If you remove the StringFormat, the time displays in 24-hour format with seconds.

    Unfortunately, this is not something Telerik can fix.  Microsoft formatting for the TextBlock doesn't fully understand the TimeSpan type.

    So maybe a converter is the only solution.
  6. Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 30 Mar 2010 Link to this post

    Hi Terry,

    It seems that this is an appropriate way to achieve this.

    Sincerely yours,
    Kaloyan
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top
DevCraft banner