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

How use Mask property of GridViewMaskBoxColumn

4 Answers 336 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tariq
Top achievements
Rank 1
Tariq asked on 02 Jan 2009, 08:38 AM

I am using GridViewMaskBoxColumn and want to restrict the user to input digist as follows:  "00.0". I mean that the user is allowed only to insert digits in this column with two digits on the left side and one digit on the right side of the decimal position (very simple).    Please note that I don't want to use GridViewDemicalColumn as it forces Spin Editor while I want to use plain text editor.

How can I achieve this.

Taiq Changgez

4 Answers, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 05 Jan 2009, 04:17 PM
Hello Tariq,

Thank you for your question.

You can achieve this by setting the "Mask" property of the GridViewMaskBoxColumn to "##.#" and the MaskType to "Standard".

I hope this will help you to achieve the desired behavior.

You can read more about using the RadMaskedEditBox and respectively the GridViewMaskBoxColumn here:

http://www.telerik.com/help/winforms/ui_maskedworking.html

Do not hesitate to write back if you need further assistance.

All the best,
Deyan
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Tariq
Top achievements
Rank 1
answered on 06 Jan 2009, 11:00 AM
I set the Mask property of the GridViewMaskBoxColumn to "##.#" as suggested by you, but it did not work. At run-time it does not let my enter any number. I tried changing the Mask to different settings such as  "####.##" but the behavior at run-time did not change. 

Please note that there is no "MaskType" property as mentioned in your reply. This property does not exist in the Property Builder and also if I try to type it in the code, it gives me compile time error saying that there is no such property. I am using 2008 - Q3 version.

Tariq Changgez
0
Deyan
Telerik team
answered on 06 Jan 2009, 05:47 PM
Hi Tariq,

The MaskType property of the GridViewMaskBoxColumn is not available in the Q3 2008 version of the RadGridView. Please, apologize us for the inconvenience. I would suggest downloading and updating to the Q3  2008 SP1 version which should be available in the Download Section of your account at Telerik.com.

Moreover, I have researched your question a little bit more and I found out that a little workaround will be needed, so that you can achieve the desired behavior. I have prepared a code snippet that demonstrates how to do this and I am going to explain it here as well.

When you set the Mask of the GridViewMaskBoxCulumn to "##.#" you are will restrict the user to type only float values containing two integers before the floating point and one after it. When you save the user input, however, it will display as an integer with 3 digits, because the RadGridView does not recognize the float pattern specified with the mask. Therefore, I suggest you to implement a handler for the CellEndEdit event of the RadGridView, read the input value from the GridViewMaskBoxColumn cell and divide it by 10 in order to receive the desired value. Here is how I am doing this:

private void On_CellEndEdit(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e) 
            //See if a GridViewMaskBoxColumn cell has been edited. 
            //In this case the GridViewMaskBoxColumn is at index 0. 
    if (e.ColumnIndex == 0) 
    { 
       float floatValue; 
       //Try to parse the input. 
       if (float.TryParse(this.radGridView1.ActiveEditor.Value.ToString(), out floatValue)) 
       { 
           //Divide the value by 10 so that a float value with
           //two digits on the left and one on the right side of
           //the floating point is acquired 
           this.radGridView1.ActiveEditorCell.Value = floatValue / 10; 
       } 
    } 

 
Note that you should follow the instructions I gave you in my previous post including the implementation of the CellEndEdit event handler explained here.

I hope this will help you through.

Kind regards,
Deyan
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Erin
Top achievements
Rank 1
answered on 26 Feb 2009, 02:44 PM
I had an issue with the cell value not having the mask applied.  My columns are for phone and SSN numbers so the method described didn't work for me.  I came up with this solution and it works for all instances.

Public Sub someGridView_CellEndEdit(ByVal sender as ObjectByVal e as Telerik.WinControls.UI.GridViewCellEventArgs)  handles someGridView.CellEndEdit  
' If the Grid's active editor has a value and the type of the active editor is a RadMaskededitBoxEditor then set the current cell's value  
If not someGridView.ActiveEditor.Value Is Nothing AndAlso Typeof(someGridView.ActiveEditor) is RadMaskedEditBoxEditor Then 
'cast someGridview's active editor as a radmaskededitboxeditor to get to the MaskTextBox property and use it's MaskEditText property for the cell's value  
    someGridView.CurrentCell.Value = Ctype(someGridView.ActiveEditor, RadMaskedEditBoxEditor).MaskTextBox.MaskEditText  
End if  
End Sub 
Tags
GridView
Asked by
Tariq
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Tariq
Top achievements
Rank 1
Erin
Top achievements
Rank 1
Share this question
or