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

    hi,

    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}"/>
    </style>

    in GridViewDataColumn im assigning this below code

    CellStyle="{StaticResource CurrencyValueStyle}"

    But, im getting some XAML parser error.

    Where exaclty im doin wrong? please help

    Regards,

    Avi


  2. Vanya Pavlova
    Admin
    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">
            <Grid.Resources>
                <Style x:Key="ss" TargetType="telerik:GridViewCell">
                    <Setter Property="Background" Value="Red"/>
                </Style>
            </Grid.Resources>
            <telerik:RadGridView x:Name="radGridView" AutoGenerateColumns="False" GroupPanelStyle="{StaticResource GridViewGroupPanelStyle1}" >
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn CellStyle="{StaticResource ss}" DataMemberBinding="{Binding LastName}" Header="Last Name"/>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Married}" Header="Is Married"/>
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>
        </Grid>


    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:

    <UserControl.Resources>   
        <sys:String x:Key="DataFormatString">{0:P}</sys:String>               
    </UserControl.Resources>
    ..
    <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

    Hello,

    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):

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

    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:RadGridView.SortDescriptors>
    		<telerik:SortDescriptor Member="ClaimDate" SortDirection="Descending"></telerik:SortDescriptor>
    	</telerik:RadGridView.SortDescriptors>
    	<telerik:RadGridView.Columns>
    		<telerik:GridViewDataColumn DataMemberBinding="{Binding ClaimDate}" Header="{Binding Source={StaticResource GridStrings}, Path=ClaimDate}" UniqueName="ClaimDate" 
                                                DataFormatString="{Binding Source={StaticResource DataFormatString}}"/>
    	</telerik:RadGridView.Columns>
    </telerik:RadGridView>

    Thanks,

    Christopher
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 21 May 2012 Link to this post

    Hi,

     Please define your resource like so:

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

    Regards,
    Didie
    the Telerik team

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

Back to Top