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

Location or Culture specification for one column

8 Answers 363 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
christina noel
Top achievements
Rank 1
christina noel asked on 17 Nov 2011, 09:51 PM
I am building a radgridview that has a date column and two currency columns (code below). I need my date column to show in the user's default culture (specified via the html object "culture" param), but the currency columns need to be in whatever currency the user is currently working with. I have the language code for the currency (e.g. "fr-CA") in a property of my ViewModel, but I can't figure out how to use that to change the language of just those two columns without messing with the culture of the date column. I can't use it as a converterparameter or a converterculture for the binding because it itself is a binding.

It needs to work for both viewing and for editting, so if the currency culture uses a comma as the decimal separator, you type commas into the edit box.

I'd appreciate any help I can get!

--Christina

<telerik:RadGridView x:Name="grdFiles"  SelectionMode="Extended" ItemsSource="{Binding JournalItemView}" AutoGenerateColumns="false" SelectionUnit="FullRow" CanUserSelect="False" IsSynchronizedWithCurrentItem="false"  ShowColumnFooters="False" RowEditEnded="grdFiles_RowEditEnded" AddingNewDataItem="grdFiles_AddingNewDataItem" RowLoaded="grdFiles_RowLoaded" >          
    <telerik:RadGridView.Columns>
        <telerik:GridViewSelectColumn UniqueName="SelectColumn"/>
        <telerik:GridViewDataColumn UniqueName="Date" DataMemberBinding="{Binding DateValue}" DataFormatString="{}{0:d}" >
            <telerik:GridViewDataColumn.Header>
                   <TextBlock>
                        <Run Text="{Binding Labeller, Source={StaticResource ViewModel}, ConverterParameter=Date, Converter={StaticResource LabelStringConverter}, FallbackValue=Date}"/>
                        <Run Text="*" Foreground="Red"/>
                    </TextBlock>
            </telerik:GridViewDataColumn.Header>
        </telerik:GridViewDataColumn>
       <telerik:GridViewDataColumn UniqueName="Debit" DataMemberBinding="{Binding Debit}"
DataFormatString="{}{0:c}"
   Width="120" TextAlignment="Right" HeaderTextAlignment="Right"
                                    Header="{Binding Labeller, Source={StaticResource ViewModel}, ConverterParameter=Debit, Converter={StaticResource LabelStringConverter}, FallbackValue=Debit}"
                                    />
        <telerik:GridViewDataColumn UniqueName="Credit"  Width="120" TextAlignment="Right" HeaderTextAlignment="Right"
                                    DataMemberBinding="{Binding Credit}" DataFormatString="{}{0:c}"
                                    Header="{Binding Labeller, Source={StaticResource ViewModel}, ConverterParameter=Credit, Converter={StaticResource LabelStringConverter}, FallbackValue=Credit}"
                                    >
        </telerik:GridViewDataColumn>
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

8 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 23 Nov 2011, 07:44 AM
Hello Christina Noel,

First, let me clarify the scenario - you want to have a specific culture for the whole grid (fr-CA for example), edit the numeric values accordingly (period/comma as separator) and still only for the currency columns to be able to define 'Pounds' for example. Am I right or am I missing something ? If so, how do you specify what is the currency you want to work with ? Do you change it from a button for instance or it depends on something else ? 
 

Kind regards,
Maya
the Telerik team

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

0
christina noel
Top achievements
Rank 1
answered on 23 Nov 2011, 04:13 PM
The whole grid and most columns will be in the "user's culture" -- I specify this by setting the culture and uiculture parameters in the html for my silverlight object. This culture will set the language for string localization, date formatting, and most number columns. Then, it is a requirement that the user be able to work in currencies other than the one for his culture. This means having a grid column that will display and input in the currency's number format. (So if, for example, they're inputting into the system from an invoice in a different currency, they can type it just as they see it).

Right now, the Ietf string representing the currency culture is a property in my viewmodel. It is actually set from either a combo box on the html page or from the underlying data in the database.

Since I first asked this question, I have implemented a column that inherits from GridViewDataColumn with a "LanguageCode" dependency property.
public String LanguageCode
{
    get { return (String)GetValue(LanguageCodeProperty); }
    set { SetValue(LanguageCodeProperty, value); }
}
 
// Using a DependencyProperty as the backing store for CanEdit.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty LanguageCodeProperty =
    DependencyProperty.Register("LanguageCode", typeof(String), typeof(MPGridDataColumn),
    new PropertyMetadata(CultureInfo.CurrentCulture.Name,
        ((sender, e)=> (sender as MPGridDataColumn).DataMemberBinding.ConverterCulture=new CultureInfo(e.NewValue as String))));

Then, in my grid I bind LanguageCode to my ViewModel property.

This works great for the initial grid load, but I can't get it to update when the ViewModel property changes after the initial rendering. I'm not sure yet if the disconnect is in the grid display (so I just have to refresh the view) or in the binding.

--Christina
0
Maya
Telerik team
answered on 28 Nov 2011, 02:29 PM
Hi Christina,

I would recommend you to work with DataFormatString directly, not with the culture. So, if you define your column initially similar to:

<telerik:GridViewDataColumn DataMemberBinding="{Binding StadiumCapacity}" DataFormatString="{}{0:#.#}$"/>
 
You can try the following:
(this.clubsGrid.Columns[3] as GridViewDataColumn).DataFormatString = "{0:#.#}£";

However, if you want to have the same behavior in edit mode, you can define CellEditTemplate, place TextBox for example and bind its Text setting the StringFormat of the Binding directly.

All the best,
Maya
the Telerik team

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

0
christina noel
Top achievements
Rank 1
answered on 28 Nov 2011, 02:55 PM
Unfortunately, this is NOT a helpful suggestion. The conversion from language code to format string is nearly impossible to get right, and full of tweaks and bobbles. You need to make sure that you put the symbol in front or behind as appropriate; you need to make sure you have the right number of decimals; the list goes on and on. All that information is available in the CultureInfo object, but it is extremely scattered. Every time I've tried to manually construct the format string (for our older ajax grids), it's backfired on me by not working on some currency that I didn't know we supported. It would be great if there was a function on the culture info object that would give you the currency format string, but if it exists, I've never been able to find it.

--Christina


0
christina noel
Top achievements
Rank 1
answered on 28 Nov 2011, 10:08 PM
I also am now running into the problem of localizing the aggregate function outputs for these specialized currency columns. I just need a "Sum" function that will respect the languagecode for the rest of the column. Any ideas on how to do that with the current sum function, or on how to create a new one that will work? If I have to, I'll just create a footer that binds to a property that represents the sum instead of using the aggregate, but that creates the problem of making sure it reliably updates.

--Christina
0
Maya
Telerik team
answered on 01 Dec 2011, 02:23 PM
Hello Christina Noel,

I would recommend you to run through this demo for a reference on how to customize the footers. If you want to localize the caption, you can follow the approach illustrated in this article
Let me know in case you need any further assistance.

 

All the best,
Maya
the Telerik team

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

0
Bhavika
Top achievements
Rank 1
answered on 06 Nov 2017, 03:45 PM

Hello,

I want to apply different currency culture for kendo grid column.

e.g. In kendo grid I have multiple columns. 'Price' is one of them.

for Record 1's price column : I want to apply '$' currency culture.

for Record 2's price column : I want to apply 'Euro' currency culture.

for Record 3's price column: I want to apply 'Pound(GBP) currency culture.

Please can you suggest me how can I implement different currency culture for kendo grid data column, I am new to kendo UI.

Thanks & Regards,

Bhavika

 

0
Dinko | Tech Support Engineer
Telerik team
answered on 09 Nov 2017, 10:13 AM
Hello Bhavika,

You have placed your question in the forum for RadGridView for Silverlight and it is not related to Kendo UI. You can place a new thread in the corresponding forum Kendo UI. This way your questions will be handled by the correct team.

Regards,
Dinko
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
christina noel
Top achievements
Rank 1
Answers by
Maya
Telerik team
christina noel
Top achievements
Rank 1
Bhavika
Top achievements
Rank 1
Dinko | Tech Support Engineer
Telerik team
Share this question
or