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

GridViewMaskBoxColumn with Culture

3 Answers 195 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 1
Alexander asked on 03 Jun 2010, 10:14 AM
I use RadGridView to edit some data and declare the GridViewMaskBoxColumn in the following way

            GridViewMaskBoxColumn widthColumn = new GridViewMaskBoxColumn();
            widthColumn.HeaderText = "Width";
            widthColumn.FieldName = "Width";
            widthColumn.MaskType = MaskType.Numeric;
            widthColumn.Mask = "f2";
            widthColumn.FormatInfo = CultureInfo.CurrentCulture;
            BaseGridView.MasterGridViewTemplate.Columns.Add(widthColumn);

As u can see I even set the culture manually and during debug I see that the culture is "ru-RU" that means I will see the numbers separated width "," instead of "."

That's works fine I see the comma clearly.
But then I set
            BaseGridView.CellValidating += new CellValidatingEventHandler(BaseGridView_CellValidating);
to validate if the user entered the data in a valid range for my application.
When debug reaches this action i can see CellValidatingEventArgs.Value defined as "11.11" instead of "11,11" as was shown in the editor.
This leads application to an exception when i try set this value to a float property.
What have i done wrong?






3 Answers, 1 is accepted

Sort by
0
Alexander
Top achievements
Rank 1
answered on 07 Jun 2010, 08:59 AM
up
0
Accepted
Alexander
Telerik team
answered on 08 Jun 2010, 03:39 PM
Hello Alexander,

GridViewMaskBoxColumn has a known issue concerning handling of decimal separators in different cultures. We will address it in a future version.

As a work around you can set the culture of RadMaskedEditBoxEditor and change the decimal separator in the CellEndEdit event handler:
private CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture("ru-RU");
 
Application.CurrentCulture = cultureInfo;
 
this.radGridView1.CellEditorInitialized += new GridViewCellEventHandler(radGridView1_CellEditorInitialized);
this.radGridView1.CellEndEdit += new GridViewCellEventHandler(radGridView1_CellEndEdit);
 
private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
    RadMaskedEditBoxEditor editor = this.radGridView1.ActiveEditor as RadMaskedEditBoxEditor;
 
    if (editor != null)
    {
        editor.MaskTextBox.RadMaskBoxProperties.Culture = cultureInfo;
    }
}
 
private void radGridView1_CellEndEdit(object sender, GridViewCellEventArgs e)
{
    GridViewCellInfo cell = this.radGridView1.Rows[e.RowIndex].Cells["column1"];
    cell.Value = cell.Value.ToString().Replace('.', ',');
}

I hope this helps.

Best regards,
Alexander
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Alexander
Top achievements
Rank 1
answered on 08 Jun 2010, 04:49 PM
Already used
           
            GridViewDecimalColumn widthColumn = new GridViewDecimalColumn();
            widthColumn.HeaderText = "Width";
            widthColumn.FieldName = "Width";
            widthColumn.FormatString = "{0: 0.00;0.00;none}";
            widthColumn.DataType = typeof(double);
            BaseGridView.MasterGridViewTemplate.Columns.Add(widthColumn);

It's Ok with cultures
Tags
GridView
Asked by
Alexander
Top achievements
Rank 1
Answers by
Alexander
Top achievements
Rank 1
Alexander
Telerik team
Share this question
or