We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Changing mask based on first character

Thread ID:

Created:

Updated:

Platform:

Replies:

118587 Mar 20,2015 03:16 PM Mar 25,2015 01:43 AM WPF 3
loading
Tags: MaskedTextBox
James
Asked On March 20, 2015 03:16 PM

Hello,

I'm trying to implement certain functionality with the MaskedTextBox but I'm running into issues. I was hoping that somebody might have some insight.

What I want is for the mask to change based on the first character in the MaskedTextBox. Initially the MaskedTextBox is empty and the mask is empty but if the user were to type in 1, the mask would be "C-0000" if the user typed in 2 instead, then it would be "C-LLLL".

I've tried changing the mask in the event handler for TextChanged and ValueChanged but this seems to push the cursor back to the beginning of the text.

Another issue is that if I use 1 first then highlight all and press 2, the mask is still "C-0000".

The relevant code is:

<sync:MaskedTextBox Height="25"
                            Width="200"
                            ValueChanged="MaskedEditor_ValueChanged"
                            Name="MaskedEditor"
                            PromptChar="_"/>

        private void MaskedEditor_ValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (MaskedEditor.Value[0] == '1')
                MaskedEditor.Mask = "C-0000";
            else if (MaskedEditor.Value[0] == '2')
                MaskedEditor.Mask = "C-LLLL";
        }

Any help is appreciated. Thank you.

Vijayalakshmi Roopkumar [Syncfusion]
Replied On March 23, 2015 04:15 PM

Hi James,

Thank you for contacting the Syncfusion Support,

We have prepared a sample that tries to meet your requirement. In our sample we have handled the provided code in the PreviewKeyDown event, so that the cursor will be placed correctly and also when selected the 1 in the MaskedTextBox , the second value Mask property does not remain the same as the first value. Please download the sample using the below link:

Sample:MaskedTextbox_118587.zip

Please let us know if you have any other concerns,

Regards,
Vijayalakshmi V.R.



James
Replied On March 24, 2015 01:00 PM

Thanks for this sample Vijayalakshmi.

I'm working with it right now and it looks like with your help I will be able to achieve what I need.

James

Saranya CJ [Syncfusion]
Replied On March 25, 2015 01:43 AM

Hi James,

Thank you for your update. Please let us know if you require any other assistance on this.

Regards,

Saranya

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;