I'm having problems with the DataGrid not respecting the minimum I set - I want it to be able to accept negative values, but it simply will not.
I've put some code below, and here is a link to a sample project that has the problem.
<
Grid
Background
=
"{ThemeResource ApplicationPageBackgroundThemeBrush}"
>
<
grid:RadDataGrid
x:Name
=
"grid"
DataContext
=
"{StaticResource ViewModel}"
ItemsSource
=
"{Binding Items}"
UserEditMode
=
"External"
UserGroupMode
=
"Disabled"
AutoGenerateColumns
=
"False"
>
<
grid:RadDataGrid.Columns
>
<
grid:DataGridTextColumn
PropertyName
=
"Country"
Header
=
"Country"
/>
<
grid:DataGridTextColumn
PropertyName
=
"Capital"
Header
=
"Capital"
/>
<
grid:DataGridNumericalColumn
PropertyName
=
"Amount"
Header
=
"Amount"
>
<
grid:DataGridNumericalColumn.CellEditorStyle
>
<
Style
TargetType
=
"input:RadNumericBox"
>
<
Setter
Property
=
"Minimum"
Value
=
"-1000"
/>
<
Setter
Property
=
"Maximum"
Value
=
"1000"
/>
<
Setter
Property
=
"ValueFormat"
Value
=
"{}{0,0:C2}"
/>
</
Style
>
</
grid:DataGridNumericalColumn.CellEditorStyle
>
</
grid:DataGridNumericalColumn
>
</
grid:RadDataGrid.Columns
>
<
grid:RadDataGrid.Commands
>
<
commands:DataGridUserCommand
Id
=
"CommitEdit"
Command
=
"{Binding Source={StaticResource ViewModel}, Path=MyCommand}"
/>
</
grid:RadDataGrid.Commands
>
</
grid:RadDataGrid
>
</
Grid
>
9 Answers, 1 is accepted
Thank you for providing the sample. We are currently investigating the behavior. I will update the thread once we have more information on the matter.
Have a great rest of the week.
Regards,
Stefan Nenchev
Progress Telerik
I have attached a sample project which shows how to achieve the desired behavior. Please have a look at the custom command which is executed when starting to edit the DataGrid.
Regards,
Stefan Nenchev
Progress Telerik
Hi Stefan,
Is there supposed to be an CustomExternalEditor.cs file in that project?
Regards,
Jeremiah
I started testing another approach but changed it and decided to delete this file. You can disregard it and check the CustomBeginEditCommand implementation.
Regards,
Stefan Nenchev
Progress Telerik
The method you are using works, but inconsistently. Sometimes it allows for negative values, but other times it does not. I suspect this is because of the asynchronous nature of the code you are using?
I doubt it is of much consequence, but I should note that I have to use the x86 configuration, as I do not have the emulators installed to run the code as ARM.
Indeed, the approach I have provided is just a workaround and might not be ideal as we have not fully tested it. You can create an issue in the GitHub repository regarding the behavior and if you manage to identify the problematic part of the source code and provide a fix - to create a pull request. Any additional information will be appreciated as well. Thank you for the efforts!
Have a great week.
Regards,
Stefan Nenchev
Progress Telerik
I was unable to find a solution to my own project, so I ended up modifying the library directly. The following file has the default minimum and maximum values:
UI-For-UWP/Controls/Primitives/Primitives.UWP/RangeBaseControls/RangeControlBase.cs
What I did was to set the default values to Double.MinValue and Double.MaxValue.
I don't see this as a great solution for all projects that use the libraries (it might affect other controls like sliders), but for the purpose of my own project it will suffice.
Ideally I would find the root cause of the setter properties not being respected, but I am not experienced enough in debugging Setters in XAML, or in debugging third party libraries.
Thank you for the additional information provided. I have added some points to your account as the approach might be useful for other users that come across the behavior. In the meantime, I have also logged the behavior as a bug in our internal system and you can track its progress on the following link from our Ideas & Feedback portal - DataGrid: NumericEditor not respecting the minimum value set. I suggest you subscribe to the item in order to receive automatic notifications.
Have a great rest of the week.
Regards,
Stefan Nenchev
Progress Telerik