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

Data of different type in the same column

1 Answer 50 Views
GridView
This is a migrated thread and some comments may be shown as answers.
jeremy
Top achievements
Rank 1
jeremy asked on 03 Jun 2011, 04:59 AM
Hi,
   One column which type is GridViewMaskedTextBoxColumn in my Columns of RadGridView, User can input data of  three types, string like "22232//abcd", integar like 123, double like 123.00. I user PreparingCellForEdit Event to initialize the EditingElement which is RadMaskedTextBox,
private void rgv_PreparingCellForEdit(object sender, GridViewPreparingCellForEditEventArgs e)
       {
           if (e.Column.UniqueName == "IsRadMaskedTextBoxColumn")
           {
               RadMaskedTextBox tbNumbersArea = e.EditingElement as RadMaskedTextBox;
               
               if (e.Row.DataContext != null && e.Row.DataContext is CustSetbihyoItem)
               {
                   CustSetbihyoItem custItem = e.Row.DataContext as CustSetbihyoItem;
                   if (custItem.Unit == DicUnit[0] || custItem.Unit == DicUnit[2])
                   {
                       tbNumbersArea.MaskType = MaskType.Numeric;  //Input integer
                       tbNumbersArea.Mask = "d";
                       tbNumbersArea.Value = 1;
                   }
                   else if (custItem.Unit == DicUnit[10])
                   {
                       RwNumberArea RwNumberArea = new RwNumberArea();  //One child window be show
                       RwNumberArea.ShowDialog();
                   }
                   else 
                   {
                       tbNumbersArea.MaskType = MaskType.Numeric;  // Input Double
                       tbNumbersArea.Mask = "n2";
                       tbNumbersArea.Value = Menseki;  //the default is 100.00
                   }
                }
           }
       }
when I input the 200.00 according to the third condition(look the code), the  mask of RadMaskedTextbox is "n2", but when I finish editing , it displays 200, I need 200.00, how to solve it ?
Kind Regards
Jeremy

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 08 Jun 2011, 01:23 PM
Hi jeremy,

This would be the expected behavior since the mask type is defined only for the editing element. In fact the GridViewMaskedTextBoxColumn ensures that the RadMaskedTextBox will be used while in edit-mode, not in view-mode. What you may try to do is to set the DataFormatString property of the column:

<telerik:GridViewMaskedTextBoxColumn UniqueName="RadMaskedTextBoxColumn"
                                   DataMemberBinding="{Binding StadiumCapacity}"
                                   DataFormatString="{}{0:N2}"/>

On a side note, I would recommend you to set value using the underlaying data item's properties, not by using a visual element - the editing element in this case. 

Best wishes,
Maya
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
Tags
GridView
Asked by
jeremy
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or