Results 1 to 2 of 2

Thread: Edit Mask for textbox input

  1. #1

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a new Maserati down a dead end street
    Posts
    4,256

    Edit Mask for textbox input

    A textbox on my Windows form is a DevExpress TextEdit.
    I want to create an input mask for it, but it's a bit tricky because it needs to be flexible.
    It is for inputting radio frequencies and when it's numeric input we want it to have a decimal with 5 digits after the decimal, treating trailing zeroes as significant and not dropping them. So some input would be nnn.00000 or nn.00000.
    The fields maps to a sql server column with type varchar(10). It doesn't have to be numeric. We want to allow input such as 123.45000 but also None and unk (for unknown) and really any free-form input the user wants to assign.
    So I'm thinking, have a numeric mask but as soon as the user types a non-numeric character in the textedit, toss out the mask and let them input whatever they want.
    I am going to start working on this but if anyone has a great idea or helpful tip, I'll take it.
    Thanks!
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  2. #2

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a new Maserati down a dead end street
    Posts
    4,256

    Re: Edit Mask for textbox input

    I know what I am going to do. Where I need this code is in a wizard so I am going to let them enter the frequency on the first wizard page. That frequency carries over to the next wizard page. So if on page 1 they enter "97.3", on page 2 I will display it as "97.30000". If they want to, they can edit it on page 2. (Sometimes my boss doesn't like edits and locking people into doing things because there could be a reason they stray from the norm). If on page 1 they entered "None", I will do nothing. Here is the code I am running on the NextClick() event (txtFrequency is the textedit on p. 1 and txtTXFrequency is its name on p. 2, and there's also a txtRXFrequency):
    Code:
                switch (e.Page.Name)
                {
    
    
                    case "wizardPage1":
    
                        NumberFormatInfo nfi = new CultureInfo("en-US", false).NumberFormat;
                        nfi.NumberDecimalDigits = 5;
                        //txtTXFrequency.Text = txtFrequency.Text;
                       
                        //txtTXFrequency.Text = (Convert.ToDouble(txtFrequency.Text).ToString("N", nfi));
    
                        if (Double.TryParse(txtFrequency.Text, out double number))
                        {
                            if (number != 0)
                                //txtTXFrequency.Text = (Convert.ToDouble(txtFrequency.Text).ToString("N", nfi));
                                txtTXFrequency.Text = number.ToString("N", nfi);
                            else
                                txtTXFrequency.Text = txtFrequency.Text;
                        }
                        else
                        {
                            txtTXFrequency.Text = txtFrequency.Text;
                        }
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width