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

Changing a column's mask from a keypress in the editor

1 Answer 102 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bill
Top achievements
Rank 1
Bill asked on 05 Oct 2012, 10:16 PM
I have a grid containing a GridViewMaskBoxColumn.  I want the mask on the cell to change when I hit the F4 key with the cell editor active.  Unfortunately when I change the column's Mask in the RadMaskedEditBoxEditorElement's KeyUp event handler while the editor is open it doesn't have an immediate effect; I have to switch to a different cell before the new mask takes effect.  How do I get the mask change to take immediate effect in the editor?

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 09 Oct 2012, 01:36 PM
Hello Bill,

Thank you for contacting Telerik support.

I was able to change the mask when user press the F4 key while the editor is active. Please refer to the code below:
//Add the column
GridViewMaskBoxColumn mbc = new GridViewMaskBoxColumn("Value");
mbc.FieldName = "Value";
mbc.Name = "Value";
mbc.HeaderText = "Value";
mbc.MaskType = MaskType.Standard;
mbc.Mask = "###";
radGridView1.Columns.Add(mbc);
 
//wire to the event
private void radGridView1_CellEditorInitialized(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
{
            if (radGridView1.CurrentColumn.Name.ToString() == "Value")
            {
                RadMaskedEditBoxEditor cmb = radGridView1.ActiveEditor as RadMaskedEditBoxEditor;
                if (cmb != null)
                {
((RadMaskedEditBoxEditorElement)(cmb).EditorElement).KeyUp -= new KeyEventHandler(Editor_KeyUp);

                    ((RadMaskedEditBoxEditorElement)(cmb).EditorElement).KeyUp += new KeyEventHandler(Editor_KeyUp);
                }
            }
        }
 
//Change the mask
void Editor_KeyUp(object sender, KeyEventArgs e)
{
            if (e.KeyCode == Keys.F4)
            {
                RadMaskedEditBoxEditorElement editor = (RadMaskedEditBoxEditorElement)sender;
                if (editor.Mask == "###")
                {
                    editor.Mask = "########";
                }
                else
                {
                    editor.Mask = "###";
                }
            }
 }

I hope this will help. Please let me know if you need any further assistance. All the best,
Peter
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Bill
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or