When decimal . is pressed change decimal spot

7 posts, 1 answers
  1. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 12 Apr 2011 Link to this post

    My mask is #2.2
    If I have a current value as 10.55.  Then I put my cursor between the 1 and the 0.  When I press the '.'  I want the number to change to 1.055 (or if it's #2.2   1.06 or 1.05).  Is there a way to do this?  Right now it just skips past the 0 and keeps the 10.
  2. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 13 Apr 2011 Link to this post

    Maybe I should be asking, is it ok to use the ValueChanged with a maskedInput to do this?  Is it going to override any of the other masking?
  3. DevCraft banner
  4. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 13 Apr 2011 Link to this post

    I almost have it, but I can't get the current cursor position.  Or it always changes to 3.  I need to get the cursor postion before the telerik control moves the cursor. SelectionStart isn't the right value when I press '.' ,   it's ok when I press a regular number though.



    private void textBoxHours_TextInputStart(object sender, System.Windows.Input.TextCompositionEventArgs e)
    {
        if (e.Text.Equals("."))
        {
            int testi = this.textBoxHours.SelectionStart;
        }
    }
  5. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 18 Apr 2011 Link to this post

    Hi danparker276,

    Have you tried setting the SelectionOnFocus property to "Unchanged"? The control handles internally the selection start. You could also try using Dispatcher.BeginInvoke() to change the caret's position in the ValueChanged event.

    Regards,
    Alex Fidanov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 18 Apr 2011 Link to this post

    SelectionOnFocus doesn't help, like you said it's handeled internally before textinputStart.
    The start postion is always 3 when I press a '.' , I have no way of knowing if they pressed it
    at starting position 0,1, 2,3...

    I'll probably have to take off the mask and do the mask myself.

    Should I open up a feature request for it to give you the option to shift the number over if a '.' is pressed? We write applications for accounts that tab through many numeric numbers and are very used to that.
  7. Answer
    Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 22 Apr 2011 Link to this post

    Hi danparker276,

    I apologize for the late response. I think the TextInputStart event would not be appropriate for this. Here is a code snippet that you can use with the KeyDown event:

    mask.AddHandler(RadMaskedNumericInput.KeyDownEvent, new KeyEventHandler(mask_KeyDown), true);

    private void mask_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Decimal)
        {
            RadMaskedNumericInput numericInput = sender as RadMaskedNumericInput;
            double? value = numericInput.Value;
            int selStart = numericInput.SelectionStart;
            if (value.HasValue)
            {
                string currencySeparator = numericInput.Culture.NumberFormat.CurrencyDecimalSeparator;
                string newValueStr = value.Value.ToString().Replace(currencySeparator, string.Empty).Insert(selStart, currencySeparator);
                double newValue = 0;
                if(double.TryParse(newValueStr, System.Globalization.NumberStyles.Any, numericInput.Culture, out newValue))
                {
                    numericInput.Value = Math.Round(newValue, 2);
                }
            }
        }
    }
    Please note that this code checks only for the Decimal key on the numeric keypad. You would have to add checks for the Oem keys (comma and point).

    Kind regards,
    Alex Fidanov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 22 Apr 2011 Link to this post

    Thanks works great, brilliant!!! 
Back to Top
DevCraft banner