DataFormatString style setter for Money

4 posts, 0 answers
  1. avinash
    avinash avatar
    12 posts
    Member since:
    Feb 2011

    Posted 26 Aug 2011 Link to this post


    I have many gridviews with Currency Column. I have Created Style setter for DataFormat String. Below is the code

    <style x:Key="CurrencyValueStyle" TargetType="telerik:GridViewDataColumn">
     <Setter Property = "DataFormatString" value="{}{0:#,##0.00}"/>

    in GridViewDataColumn im assigning this below code

    CellStyle="{StaticResource CurrencyValueStyle}"

    But, im getting some XAML parser error.

    Where exaclty im doin wrong? please help



  2. Vanya Pavlova
    Vanya Pavlova avatar
    2019 posts

    Posted 26 Aug 2011 Link to this post

    Hello Avinash,


    Since columns in RadGridView are not visual objects you cannot create a style targeted at a Column. If you want to apply a style to GridViewCells within this column you should change the TargetType to GridViewCell:

    <Grid x:Name="LayoutRoot" Background="White">
                <Style x:Key="ss" TargetType="telerik:GridViewCell">
                    <Setter Property="Background" Value="Red"/>
            <telerik:RadGridView x:Name="radGridView" AutoGenerateColumns="False" GroupPanelStyle="{StaticResource GridViewGroupPanelStyle1}" >
                    <telerik:GridViewDataColumn CellStyle="{StaticResource ss}" DataMemberBinding="{Binding LastName}" Header="Last Name"/>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Married}" Header="Is Married"/>

    Regarding the DataFormatString you cannot reference it in a style setter. You may define a DataFormatString as a string Resource and then reference it to a column as shown below:

        <sys:String x:Key="DataFormatString">{0:P}</sys:String>               
    <telerik:GridViewDataColumn DataMemberBinding="{Binding ProductID}"                                                                    DataFormatString="{Binding Source={StaticResource DataFormatString}}"/>

    All the best,
    Vanya Pavlova
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. Christopher
    Christopher avatar
    4 posts
    Member since:
    May 2011

    Posted 21 May 2012 Link to this post


    I am using the Telerik Silverlight release Q1 2012 and attempting to set the DataFormatString of a GridViewDataColumn to a resource which is set to a date format string.

    I have done what you said (see below), but it does not appear to work for me. Am I overlooking something here?

    In my resources section (my user control is a RadWindow):

            <sys:String x:Key="DataFormatString">{}{0:yyyy/MM/dd}</sys:String>

    My RadGridView:

    <telerik:RadGridView x:Name="RadDataGrid" Grid.Row="0" SelectionMode="Single" SelectedItem="{Binding SelectedGridItem, Mode=TwoWay}"  ShowGroupPanel="False" AutoGenerateColumns="False" IsReadOnly="True" BorderThickness="0" ItemsSource="{Binding PagedSource, ElementName=DataPager}">
    		<telerik:SortDescriptor Member="ClaimDate" SortDirection="Descending"></telerik:SortDescriptor>
    		<telerik:GridViewDataColumn DataMemberBinding="{Binding ClaimDate}" Header="{Binding Source={StaticResource GridStrings}, Path=ClaimDate}" UniqueName="ClaimDate" 
                                                DataFormatString="{Binding Source={StaticResource DataFormatString}}"/>


  4. Dimitrina
    Dimitrina avatar
    3769 posts

    Posted 21 May 2012 Link to this post


     Please define your resource like so:

    <sys:String x:Key="DataFormatString">yyyy</sys:String>

    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top