DataFormatString for a custom class

6 posts, 0 answers
  1. Patrick
    Patrick avatar
    372 posts
    Member since:
    Aug 2012

    Posted 21 Jan 2014 Link to this post

    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
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 22 Jan 2014 Link to this post

    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 >>
  3. DevCraft banner
  4. Patrick
    Patrick avatar
    372 posts
    Member since:
    Aug 2012

    Posted 22 Jan 2014 Link to this post

    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
  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 22 Jan 2014 Link to this post

    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 >>
  6. Patrick
    Patrick avatar
    372 posts
    Member since:
    Aug 2012

    Posted 22 Jan 2014 Link to this post

    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
  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 24 Jan 2014 Link to this post

    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 >>
Back to Top
DevCraft banner