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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

SfNumericUpDown Select All

Thread ID:

Created:

Updated:

Platform:

Replies:

124831 Jul 1,2016 11:31 PM UTC Jul 6,2016 05:44 AM UTC UWP 3
loading
Tags: SfNumericUpDown
Matthew McDowell
Asked On July 1, 2016 11:31 PM UTC

Hello,

I am currently using the SfNumericUpDown control.  When the user focuses on the text area of the SfNumericUpDown I want the text (Number) to be highlighted (Selected) so when they enter a number it overwrites the current value.

With a normal textbox control I can do this by using the SelectAll() method button but the numericupdown does not have one, and I cant seem to find any properties that can access the textbox inside the control?

Please help

Mariappan S [Syncfusion]
Replied On July 4, 2016 02:23 PM UTC

Hi Matthew, 
  
We have created workaround sample for your requirement. In this we fetched SfNumericTextBox which present inside the SfNumericUpDown control and focus is set to it. Please download the sample from below link 
  
  
Please let us know if this sample helps. 
  
Regards, 
Mariappan S 


Matthew McDowell
Replied On July 5, 2016 07:23 AM UTC

Thankyou that worked.

I created it as an attached property to the numericupdown control with a minor change to the Box_PointerReleased event using (sender as SfTextBoxExt).SelectAll();

Thanks for your help

Here is my Attached property class

    public static class NumericUpDownAttached
    {
        public static bool GetAutoSelectable(DependencyObject obj)
        {
            return (bool)obj.GetValue(AutoSelectableProperty);
        }

        public static void SetAutoSelectable(DependencyObject obj, bool value)
        {
            obj.SetValue(AutoSelectableProperty, value);
        }

        public static readonly DependencyProperty AutoSelectableProperty =
            DependencyProperty.RegisterAttached(
                "AutoSelectable",
                typeof(bool),
                typeof(TextBoxAttached),
                new PropertyMetadata(false, AutoFocusableChangedHandler));


        private static void AutoFocusableChangedHandler(
                DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (e.NewValue != e.OldValue)
            {
                if ((bool)e.NewValue == true)
                {
                    (d as SfNumericUpDown).Loaded += numericupdown_Loaded;
                    (d as SfNumericUpDown).LostFocus += NumericUpDownAttached_LostFocus;
                }
                else
                {
                    (d as SfNumericUpDown).Loaded -= numericupdown_Loaded;
                    (d as SfNumericUpDown).LostFocus -= NumericUpDownAttached_LostFocus;
                }
            }
        }

        static bool isfocused = false;
        private static void NumericUpDownAttached_LostFocus(object sender, RoutedEventArgs e)
        {
            isfocused = true;
        }

        static SfNumericTextBox sfNumericTextBox;
       
        private static void numericupdown_Loaded(object sender, RoutedEventArgs e)
        {
            FindChildren<SfNumericTextBox>((sender as SfNumericUpDown));
        }

        public static void FindChildren<T>(DependencyObject startNode)
        {
            int count = VisualTreeHelper.GetChildrenCount(startNode);
            for (int i = 0; i < count; i++)
            {
                DependencyObject current = VisualTreeHelper.GetChild(startNode, i);
                if (current is SfNumericTextBox)
                {
                    sfNumericTextBox = current as SfNumericTextBox;
                    sfNumericTextBox.AddHandler(SfTextBoxExt.PointerReleasedEvent, new PointerEventHandler(Box_PointerReleased), true);

                    break;
                }
                else
                {
                    FindChildren<T>(current);
                }
            }
        }

        private static void Box_PointerReleased(object sender, PointerRoutedEventArgs e)
        {
            if (isfocused)
            {
                (sender as SfTextBoxExt).SelectAll();
                isfocused = false;
            }
        }
    }

and xaml usage

<Input:SfNumericUpDown LargeChange="5" MaximumNumberDecimalDigits="1" Minimum="1" Maximum="50"  FormatString="0" Common:NumericUpDownAttached.AutoSelectable="True" />


Mariappan S [Syncfusion]
Replied On July 6, 2016 05:44 AM UTC

Hi Matthew, 

Thanks for your update. 

Please let me know if you need further assistance. 

Regards, 
Mariappan S. 


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.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon 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.Close Icon

;