Binding DataFormatString

7 posts, 0 answers
  1. Maurizio
    Maurizio avatar
    3 posts
    Member since:
    Aug 2008

    Posted 08 Mar 2012 Link to this post

    Hello,

    I have this issue on RadGridView: as reported below, I have some columns. The first is an amount. The format of this amount is defined in the model with the amount value and the other fields. In run time, when I click on the amount column, the format is setted correctly but when I click on other columns, the amount format become wrong on each row.

     <tgrid:RadGridView.Columns>                                     
    <tgrid:GridViewDataColumn  DataFormatString="{Binding AmountFormatSx}" DataMemberBinding="{Binding  Path=entityData.Amount}"  Header="Amount" TextAlignment="Right">                                                 
    <tgrid:GridViewDataColumn.AggregateFunctions>                                                     
    <telerikData:SumFunction Caption="Total: "  SourceField="entityData.Importo" />
    <telerikData:CountFunction Caption="Num: " />                                                 
    </tgrid:GridViewDataColumn.AggregateFunctions>                                             
    </tgrid:GridViewDataColumn>                                             
    <tgrid:GridViewDataColumn  IsVisible="True"     SortMemberPath="entityData.DataValuta"   DataMemberBinding="{Binding Converter={StaticResource DateConverter}, Path=entityData.DataValuta}" Header="Data valuta" />                                             <tgrid:GridViewDataColumn  IsVisible="True"     SortMemberPath="entityData.DataOperazione"   DataMemberBinding="{Binding Converter={StaticResource DateConverter}, Path=entityData.DataOperazione}" Header="Data operazione" />

  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 09 Mar 2012 Link to this post

    Hi,

     I am not sure how is the AmountFormatSx defined, but can you please set the StringFormat inside the DataMemberBinding instead of using the DataFormatString property?


    If this does not help would you please share more detailed information about the formatting?

    Kind regards,
    Didie
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft banner
  4. Eduan
    Eduan avatar
    5 posts
    Member since:
    Jun 2012

    Posted 07 Aug 2012 Link to this post

    Hi

    I have the same issue as Maurizio.
    I can not use the StringFormat inside the DataMemberBinding because I need a different format string for the cell depending on the value of another column in the same row. Thus I have one column that can have any one of the following formats: {0:N2} ; {0:N1} ; {0:N0} ; {0:P0} depending on the type of row I am looking at which is determined in another column in the same row in my datasource.

    Any help would be much appreciated




  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 07 Aug 2012 Link to this post

    Hi,

     You can assign IValueConverter for this binding and return desired formatted value depending on your condition. 

    Kind regards,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Eduan
    Eduan avatar
    5 posts
    Member since:
    Jun 2012

    Posted 07 Aug 2012 Link to this post

    Hi Vlad

    I have two columns Name and Baseline, I want to format the value in Baseline depending on the value in Name.
    How would this IValueConverter work?

    <telerik:RadGridView x:Name="RadGridViewKPI" AutoGenerateColumns="False"
                                 Width="Auto" Height="Auto" Margin="5"
                                 CanUserFreezeColumns="False" RowIndicatorVisibility="Collapsed" 
                                 ItemsSource="{Binding KeyKPIs}" ColumnWidth="*" 
                                 GridLinesVisibility="Horizontal" IsReadOnly="True"
                                 VerticalGridLinesBrush="White" AutoExpandGroups="True"
                                 HorizontalGridLinesBrush="Black" ShowGroupPanel="False" CanUserInsertRows="False" CanUserDeleteRows="False" CanUserSelect="False" CanUserReorderColumns="False" IsFilteringAllowed="False">
    <telerik:RadGridView.Columns>
    <telerik:GridViewDataColumn Header="KPI" DataMemberBinding="{Binding Name}" Width="Auto" />
    <telerik:GridViewDataColumn Header="Baseline 2011" DataMemberBinding="{Binding Path=Baseline}" Width="Auto" />
    </telerik:RadGridView.Columns>
    </telerik:RadGridView>

    Thank you
  7. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 07 Aug 2012 Link to this post

    Hi,

     You can remove the Path property from the binding with the converter, cast the parameter of the converter Convert method to your item type, access desired properties to build your condition and return desired value.

    Greetings,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. Eduan
    Eduan avatar
    5 posts
    Member since:
    Jun 2012

    Posted 07 Aug 2012 Link to this post

    Thank you that resolved the issue.
Back to Top
DevCraft banner