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

DataFormatString Binding Issue

1 Answer 441 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Phillip
Top achievements
Rank 1
Phillip asked on 16 Aug 2016, 12:06 PM

Hey everyone,

I have the following problem and I hope I just oversee a simple step. (First of all: Sorry, there are lots of german words in it, but it should be understandable what the problem is.)

In picture1 (see attached files) is shown how my RadGridView looks like. Behind the RadGridView my View (using MVVM) is build like that:

<telerik:RadGridView Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="4" HorizontalAlignment="Center" ShowGroupPanel="False" ItemsSource="{Binding Path=RowPLIGFKU.Rabattstaffel, ValidatesOnDataErrors=True}" AutoGenerateColumns="False">
         <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Header="{Loc Key=PREISLISTE_LIST_RABATTSTAFFEL_ABMENGE}" DataMemberBinding="{Binding Path=[PGSTA]}"  MinWidth="80"/>
                <telerik:GridViewMaskedInputColumn Header="{Loc Key=PREISLISTE_LIST_RABATTSTAFFEL_RABATT}" DataMemberBinding="{Binding Path=[PGRAB]}"  MinWidth="80" DataFormatString="{}{0:n2} %"/>
                <telerik:GridViewMaskedInputColumn Header="{Loc Key=PREISLISTE_LIST_RABATTSTAFFEL_WERT}" DataMemberBinding="{Binding Path=[PGPRS]}" MinWidth="80" DataFormatString="{Binding RabattstaffelCurrency}" /> 
         </telerik:RadGridView.Columns>
</telerik:RadGridView>

In the second column I use the numeric DataFormatString, cause of some reason, when I use the actual percent DataFormatString ("{}{0:P}") I get 500% as result by input 5. - But why?!?! In my opinion that makes no sense. Really: Who needs this that way? 

However, my problem is in the third column, where I bind my DataFormatString to the proberty 'RabattstaffelCurrency'.

This is how I set the proberty in the ViewModel:

RabattstaffelCurrency = string.Format("{0} {1}", "{}{0:n2}", Session.Company.Value<Waehrung>(CompanyInfos.DefaultCurrency));

The result is shown in picture2. It is "{}{0:n2} EUR". And by seeing this picture it gets clear why I can't just write: {0:c2}. I need the abbreviation of the actual currency, not the symbol and that changes at the runtime by user interacitons

 

If I write it hardcoded like this "{}{0:n2} EUR" it works. I don't get a binding error or some other details, its just shows the data. And last but not least I need to say that this is a project at my work, so I have not the opportunity to implement some workarounds. 

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 17 Aug 2016, 11:12 AM
Hello Phillip,

You should explicitly set the Source of the DataFormatString binding to point to the viewmodel as with the current configuration, it is looking for a RabattstaffelCurrency property in the parent business object, which from what I understood from your reply, is not present.

I'm attaching a sample project to demonstrate what I have in mind. Please have a look at it, try to apply the same approach to your project and let me know how it goes.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
GridView
Asked by
Phillip
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Share this question
or