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. Image for the cookie policy date

SfNumericUpDown Select All

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

3 Replies

MS Mariappan S Syncfusion Team 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 



MM Matthew McDowell 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" />



MS Mariappan S Syncfusion Team 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. 


Loader.
Live Chat Icon For mobile
Up arrow icon