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

RadGridViewMaskBoxColumn - underscores appearing in field data after editing the field

5 Answers 23 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Lou
Top achievements
Rank 1
Lou asked on 09 Jan 2015, 10:44 PM
Hi, I have a RadGridView with a GridViewMaskBoxColumn that I want to use to allow the user to be able to enter any text up to 16 characters.

I have the following settings at the moment for the GridViewMaskBoxColumn:

MaskType = Standard
Mask = &&&&&&&&&&&&&&&& 

When I double click on a cell I see that underscores are used to indicate spaces. That's fine, and I'm able to edit the data. However, the underscores are persisting in my data when I move my cursor to a different field (i.e. when I'm done editing).  In other words:

Data before editing: "12345678        "
View of data while editing: "12345678________"  (underscores used to indicate spaces)
Data after editing: "12345678________"  (underscores have become part of the data).

Is there a way to prevent this? I don't want the underscores to be in my data after I'm done editing it.

Thanks for any help,

-Lou


5 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 13 Jan 2015, 04:10 PM
Hello Lou,

Thank you for writing.

The TextMaskFormat property controls whether the prompt characters will be included in the value. You can set this property to the column like this:
GridViewMaskBoxColumn col = new GridViewMaskBoxColumn();
 
col.TextMaskFormat = MaskFormat.IncludeLiterals;

Please let me know if there is something else I can help you with. 
 
Regards,
Dimitar
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Lou
Top achievements
Rank 1
answered on 13 Jan 2015, 10:07 PM
Hi Dimitar, this got me closer to what I need but I still have a problem.

With the setting you suggested (col.TextMaskFormat = MaskFormat.IncludeLiterals) I no longer get the underscores, which is good.

However, now when I type a space character as part of the string, that space is removed from the field.
So, the string "foo 123" becomes "foo123" when focus is lost from the field.
Is there a way to not have spaces removed? I want whatever I type to be reflected in the field value.

Thanks for your help,

-Lou
0
Dimitar
Telerik team
answered on 14 Jan 2015, 03:28 PM
Hello Lou,

Thank you for writing back.

I was able to reproduce the observed behaviour. Is is caused by an issue in our implementation. I have logged it in our Feedback Portal. You can track the item for status changes and add your vote for it here.

To workaround this issue you can create a custom editor:
public class MyRadMaskedEditBoxEditor : RadMaskedEditBoxEditor
{
    public override object Value
    {
        get
        {
            if (this.MaskTextBox.Mask == "&&&&&&&&&&")
            {
                return this.MaskTextBox.Value;
            }
            return base.Value;
        }
        set
        {
            base.Value = value;
        }
    }
}

You can change the default editor like this:
void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
{
    if (e.EditorType == typeof(RadMaskedEditBoxEditor))
    {
        e.EditorType = typeof(MyRadMaskedEditBoxEditor);
    }
}

Please note that you should change the value of the TextMaskFormat property to IncludeLiterals as well.

Your Telerik Points have been updated for this report.

Should you have any other questions do not hesitate to ask.


Regards,
Dimitar
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Lou
Top achievements
Rank 1
answered on 14 Jan 2015, 08:05 PM
Thanks Dimitar, I implemented the fix and it seems to work.

Below is the equivalent code for the fix in VB.Net in case it's useful for others.

-Lou


Modified control:

Imports Telerik.WinControls
Imports Telerik.WinControls.UI
 
 
Public Class MyRadMaskedEditBoxEditor
  Inherits RadMaskedEditBoxEditor
 
  Public Overrides Property Value As Object
    Get
      If (MyBase.MaskTextBox.Mask = "&&&&&&&&&&&&&&&&") Then
        Return MyBase.MaskTextBox.Value
      End If
 
      Return MyBase.Value
    End Get
 
    Set(value As Object)
      MyBase.Value = value
    End Set
  End Property
End Class

New handler:

Private Sub grd_EditorRequired(sender As System.Object, e As Telerik.WinControls.UI.EditorRequiredEventArgs) Handles grd.EditorRequired
  If e.EditorType Is GetType(RadMaskedEditBoxEditor) Then
    e.EditorType = GetType(MyRadMaskedEditBoxEditor)
  End If
End Sub


0
Dimitar
Telerik team
answered on 15 Jan 2015, 03:06 PM
Hello Lou,

Thank you for sharing the Visual Basic code.

I am glad that everything is working fine on your side now. Do not hesitate to contact us if you have other questions.
 
Regards,
Dimitar
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
Lou
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Lou
Top achievements
Rank 1
Share this question
or