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

DataFormatString for a custom class

5 Answers 113 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
Patrick asked on 21 Jan 2014, 03:01 PM
Hello,
I have a custom class that implements the ToString() and ToString(String) methods. When I want to display a property of this type in a column, the ToString() method is always called, even if I specify the DataFormatString property of the column.
Patrick

5 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 22 Jan 2014, 11:19 AM
Hi Patrick,

The ToString() method is invoked through the Binding and the value that is to be formatted as specified with DataFormatString is the resulting one.  Please note the formatting is applied after the value has been resolved.
You should apply the format when overriding the ToString() method instead.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
answered on 22 Jan 2014, 12:04 PM
Hi Didie,
as the DataFormatString is a property of GridViewBoundColumnBase, it is not resolved, I think, through the binding, which is specified in another property, DataMemberBinding.
Patrick
0
Dimitrina
Telerik team
answered on 22 Jan 2014, 12:08 PM
Hi,

I meant you can format the value you have yourself, applying a String.Format. Actually our DataFormatString does the same internally. DataFormatString is plain string.Format. To learn more please check this MSDN article: string.Format.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
answered on 22 Jan 2014, 12:26 PM
Hello Didie,
if I want to use ToString(String), it's because I want the format to change depending on the use of the value. So I cannot change the ToString() method.
Patrick
0
Dimitrina
Telerik team
answered on 24 Jan 2014, 05:22 PM
Hello Patrick,

I am afraid the DataStrignFormat will be applied over your format. Please check our online documentation 
on how it works.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Dimitrina
Telerik team
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or