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

Binding DataFormatString

6 Answers 235 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Maurizio
Top achievements
Rank 1
Maurizio asked on 08 Mar 2012, 05:09 PM
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" />

6 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 09 Mar 2012, 11:14 AM
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 >>
0
Eduan
Top achievements
Rank 1
answered on 07 Aug 2012, 08:05 AM
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




0
Vlad
Telerik team
answered on 07 Aug 2012, 08:07 AM
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.

0
Eduan
Top achievements
Rank 1
answered on 07 Aug 2012, 08:15 AM
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
0
Vlad
Telerik team
answered on 07 Aug 2012, 08:29 AM
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.

0
Eduan
Top achievements
Rank 1
answered on 07 Aug 2012, 09:17 AM
Thank you that resolved the issue.
Tags
GridView
Asked by
Maurizio
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Eduan
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or