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

[Solved] Date DataFormatString Crash

2 Answers 140 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Carl Rippon
Top achievements
Rank 1
Carl Rippon asked on 24 Aug 2010, 04:21 PM
When I create a GridView at runtime and try to format a date column, the application crashes with the following error:

"Input string was not in a correct format"

Have I got the syntax wrong for the DataFormatString property? I am trying to format the date column so that it only shows the date. My code is below which recreates the problem:

Imports Telerik.Windows.Controls
Imports System.Windows.Data
 
Partial Public Class MainPage
    Inherits UserControl
 
    Public Sub New()
        InitializeComponent()
 
        Dim StrongTypedGridView As New Telerik.Windows.Controls.RadGridView
        StrongTypedGridView.AutoGenerateColumns = False
        StrongTypedGridView.Columns.Add(New GridViewDataColumn With {.DataMemberBinding = New Binding("NameField"), .Header = "Name"})
        StrongTypedGridView.Columns.Add(New GridViewDataColumn With {.DataMemberBinding = New Binding("DateField"), .Header = "Date",
                                                                     .DataFormatString = "{}{0:d}"})
        StrongTypedGridView.ItemsSource = GetStrongData()
        LayoutRoot.Children.Add(StrongTypedGridView)
    End Sub
 
    Private Function GetStrongData() As List(Of StrongClass)
        Dim build As New List(Of StrongClass)
        build.Add(New StrongClass With {.NameField = "Fred", .DateField = DateTime.Now})
        build.Add(New StrongClass With {.NameField = "Bill", .DateField = DateTime.Now})
        Return build
    End Function
 
    Public Class StrongClass
        Public Property NameField As String
        Public Property DateField As DateTime
    End Class
End Class

2 Answers, 1 is accepted

Sort by
0
Yavor Georgiev
Telerik team
answered on 24 Aug 2010, 04:38 PM
Hi Carl Rippon,

 You need the leading {} only when you define the DataFormatString property in XAML. In code-behind you can only use {0:d}.

Greetings,
Yavor Georgiev
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
0
Carl Rippon
Top achievements
Rank 1
answered on 24 Aug 2010, 06:31 PM
Thanks, Yavor.
Tags
GridView
Asked by
Carl Rippon
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
Carl Rippon
Top achievements
Rank 1
Share this question
or