RadNumericUpDown - decimal places doesn't affect the View Model value

0 Answers 193 Views
GridView NumericUpDown
alex
Top achievements
Rank 2
Bronze
Iron
Iron
alex asked on 13 Sep 2023, 01:22 PM | edited on 16 Sep 2023, 07:39 AM

Hello,

I have a NumericUpDown with the following configuration:

1. NumberDecimalDigits=3

2. Binding to Double property in ViewModel

3. Validation (IDataErrorInfo) between 20-3000.

4. Small change 0.001

5. Big change 0.1

When I write 123.1234, I can see 123.123 in the UI but in the view model, you don't remove the additional digits.

I have the following problems:

1. Sometimes when using arrows up/down or page up/down, the 4 digit is removed. I expected that the snall/large change takes effect without removing any digits because the NumberDecimalDigits shall affect the UI.

2. On grouping/filtering, I want to apply the logic on the UI value instead of the binding value.

For 1234.1234 and 1234.1235 will be created two different groups.

In case that I have a double with 4 digits, but in the UI is configured to N3, I don't want to see two groups with same value in the Header Text. The user will not understand why there are two groups.

How can I configure the RadNumericUpDown to show 3 digits but if there is an error and the number has 4 digits to show 4 digits? (with this solution the user will understand why there is an error if he types 19.9996.

For this value, it will be round 20.000 and mark as error when minimim value 20 is allowed. Showing 4 digits will solve it.

How can I configure the Grouping and Filtering of the RadGridView to consider some double value as N3?

alex
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 13 Sep 2023, 01:26 PM | edited

Another comment on this topic.

I am not using code behind at all, so I need a solution that I can apply to the column/RadNumericUpDown styles. 

The purpose is to apply this fix on all the application easily and maintainable.

The question name is wrong. The name is:

RadNumericUpDown - removes decimal places of the View Model value

alex
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 14 Sep 2023, 03:45 PM | edited

Update: I worked all the day on a possible solution.

I created a style trigger with MultiBinding that checks if the Validation.HasError is true and the value has 4 decimals. Only for this case I updated the NumberDecimalDigits=4, when the error dissapears I updated the NumberDecimalDigits=3.

The problem is that when I update the NumberDecimalDigits, the carret index is set to -1 and the values are trimmed in the RadNumericUpDown code (see point 1 in the question).

I tried the following functionality in code behind (just for testing, after working it should be an attached property):

1. Subscribe to the ValueChangedEvent.

2. If the Validation.HasError= true and there are 4 decimals.

3. Find children of type TextBox. I cached the current Text value and carret index.

4. Updated the NumerDecimalDigits=4.

5. Restored the carret index and value to the TextBox.

6. If there is no error or number has 3 decimals, NumberDecimalDigits=3.

I handled the carret because during error with a number with 4 decimal (19.9996) if I select all the number and start typining 22, the error is gone (bigger than 20) and the carret was set to -1 when the NumberDecimalDigits was changed to 3. This workaround gives the posibility to the user to continue typing after he types 22.

This solution worked most of the time but not for the following case:

Write 19.9996 (error because minimum value shall be 20). Because of the new code, 19.9996 is shown in the TextBox instead of 20.000.

Select the '1' and replace to '2'. Error is gone and the display value is 29.999, view model value is 29.9996. Expected behavior.

Select the '2' and replace back to '1'. The display value is 19.999 and the view model value is 19.999. Unexpected behavior.

The expected value was 19.9996 and the view model value is 19.999. Why the value was changed?

 

As mentioned in a question, I can't add any workaround because changing NumberDecimalDigits or playing with small/large change sometimes affects the view model value because of the unconsistent behavior of the RadNumericUpDown. I can't cache the value and revert the e.NewValue because I can't know if the RadNumericUpDown trimmed the decimal digits or the user enters a new number without 4 digits.

No answers yet. Maybe you can help?

Tags
GridView NumericUpDown
Asked by
alex
Top achievements
Rank 2
Bronze
Iron
Iron
Share this question
or