How to force RadNumericUpDown to update from its TextBox?

1 Answer 119 Views
NumericUpDown
Jennifer
Top achievements
Rank 1
Iron
Jennifer asked on 22 Jun 2022, 09:28 PM

I'm trying to update the bound property in a RadNumericUpDown by calling UpdateSource on the Value BindingExpression.  But the Value property hasn't been updated from the internal TextBox yet.  Is there some way I can tell the RadNumericUpDown to update the Value property using the Text in its internal TextBox? 

Dilyan Traykov
Telerik team
commented on 27 Jun 2022, 08:30 AM

Hello Jennifer,

I tried to replicate the scenario you described in a small sample project, however, the Value of the RadNumericUpDown seems to be updated as expected at my end when calling the UpdateSource method of the binding.

Can you please have a look at the attached project and let me know how it differs from the setup at your end? If possible, please update the project to better resemble your setup and demonstrate your requirement and I will gladly try to suggest a viable solution.
Jennifer
Top achievements
Rank 1
Iron
commented on 20 Sep 2022, 09:07 PM

Sorry it took me so long to get back to this.  I'm trying to get it to update when clicking in the "dead space" outside of any controls.  I added a PreviewMouseDown handler to the sample project.  You can see from the Debug.Print statements that the Value isn't getting updated when UpdateSource is called.

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 22 Sep 2022, 10:59 AM

Hello Jennifer,

Thank you for the provided project.

The reason why the Value is not updated is that actually it is not bound to the Text of the TextBox. Rather, some events (such as the TextChanged event of the TextBox) are handled internally to synchronize the two values.

This works when pressing the button simply because the button takes the focus and this means that the TextBox loses the focus. The RadNumericUpDown control in turn has some logic in the LostFocus event handler that then synchronizes the two properties. You can notice that even if you remove the call to the UpdateSource method in the Click handler, the result is the same.

With this said, one approach I can suggest would be to set the UpdateValueEvent property of the control to PropertyChanged. This will ensure that on each keystroke the two properties are synchronized.

If this does not work for you, you can programmatically ensure the control loses focus when a click occurs outside of it, like so:

                Else
                    Dim ParentNumericUpDown = FocusedTextBox.ParentOfType(Of RadNumericUpDown)()
                    If ParentNumericUpDown IsNot Nothing Then
                        Debug.Print($"TextBox: {FocusedTextBox.Text}, UpDown: {ParentNumericUpDown.Value}")

                        Keyboard.ClearFocus()

                        Debug.Print($"TextBox: {FocusedTextBox.Text}, UpDown: {ParentNumericUpDown.Value}")
                    End If
                End If

For your convenience, I'm attaching the updated project with the latter approach. Please have a look and let me know if any of the proposed suggestions works for you.

Tags
NumericUpDown
Asked by
Jennifer
Top achievements
Rank 1
Iron
Answers by
Dilyan Traykov
Telerik team
Share this question
or