Current filter:
                                You should refresh the page.
                                  • Hi DevExpress-Team,

                                    I've got a simple XAF web application. This application has a business object with a int property. On the UI a ASPxSpinEdit is used for this property. I want to limit the values of this Editor form 0 to 100. So I implmented a view controller where I set the MinValue and MaxValue for this editor but it does not work and I don't know why?

                                    I attached a sample project for this issue.

                                    Thanks,
                                    Nicky

                                1 Solution

                                Creation Date Importance Sort by

                                Hello Nicky,

                                Thank you for your sample. The issue occurs because these values are overridden by ASPxIntPropertyEditor after the ControlCreated event. To execute your code later, handle the Control.Load event:

                                [C#]
                                void NumberOfUsersIntPropEditor_ControlCreated(object sender, EventArgs e) { if ((sender as ASPxIntPropertyEditor).Editor != null) (sender as ASPxIntPropertyEditor).Editor.Load += Editor_Load; }   void Editor_Load(object sender,EventArgs e) { DevExpress.Web.ASPxSpinEdit editor = sender as DevExpress.Web.ASPxSpinEdit; editor.MinValue = 0; editor.MaxValue = 100; }

                                Alternatively, create our Property Editor's descendant and override its SetupControl or CreateRestrictions method. See How to: Customize a Built-in Property Editor (ASP.NET) for details.

                                Show all comments
                                • Nicky Kuhnt 09.19.2016

                                  Thank you. It works fine!

                                • Andrew L (DevExpress Support) 09.19.2016

                                  Nicky,

                                  I am happy to hear that the problem has been resolved. Thank you for letting us know of your progress. Please feel free to contact us if you have any further difficulties. We will be happy to assist you.

                                • Yuriy Khudz 11.12.2019

                                  Hello, I try to use this solution but unsuccessfully. I cannot access to FieldName of a column of nested grid view (inline edit).
                                  I use the next code for decimal properties:

                                  [C#]
                                  private void PropertyEditorOnControlCreated(object sender, EventArgs e) { var spinEditor = (sender as ASPxIntPropertyEditor)?.Editor; if (spinEditor != null) { spinEditor.SpinButtons.ShowIncrementButtons = false; spinEditor.AllowMouseWheel = false; var propertyEditor = (ASPxPropertyEditor) sender; var columnModel = propertyEditor.Model; if (columnModel != null && columnModel.AllowEdit) { var editorValueRangeAttribute = columnModel.ModelMember.MemberInfo.FindAttribute<EditorValueRangeAttribute>(); if (editorValueRangeAttribute != null) { spinEditor.MinValue = (decimal) editorValueRangeAttribute.MinValue; spinEditor.MaxValue = (decimal) editorValueRangeAttribute.MaxValue; } } spinEditor.Load -= SpinEditor_Load; spinEditor.Load += SpinEditor_Load;//subscription for ASPxSpinEdit setup } }

                                  It works for type decimal, but for int type, I try to use

                                  [C#]
                                  private void SpinEditor_Load(object sender, EventArgs e) { var editor = sender as ASPxSpinEdit; if (editor != null) { var fieldName = "";//here I need to access field name that editor is bound to var columnModel = View.Model.Columns[fieldName]; if (columnModel != null && columnModel.AllowEdit) { var editorValueRangeAttribute = columnModel.ModelMember.MemberInfo.FindAttribute<EditorValueRangeAttribute>(); if (editorValueRangeAttribute != null) { editor.MinValue = (decimal)editorValueRangeAttribute.MinValue; editor.MaxValue = (decimal)editorValueRangeAttribute.MaxValue; } } } }

                                  Please suggest, how I can get the field name in this context? A little bit strange that first code works well for decimal, but does not work for int.

                                • Yuriy Khudz 11.12.2019

                                  Code of attribute

                                  [C#]
                                  [AttributeUsage(AttributeTargets.Property)] public class EditorValueRangeAttribute : Attribute { public EditorValueRangeAttribute(double minValue, double maxValue) { MinValue = minValue; MaxValue = maxValue; } public double MinValue { get; } public double MaxValue { get; } }

                                  Code of property

                                  [C#]
                                  [EditorValueRange(0, 10000)] [ImmediatePostData] public int Priority { get { return _priority; } set { SetPropertyValue(nameof(Priority), ref _priority, value); } }
                                • Anatol (DevExpress Support) 11.12.2019

                                  In ASPxIntPropertyEditor, the MinValue and MaxValue properties are set in the CreateRestrictions method. ASPxDecimalPropertyEditor overrides this method and does not set these properties. So, your values are not overridden in this case.
                                  A correct way to change these properties in a List View is to create an ASPxIntPropertyEditor descendant and override its CreateRestrictions method. See How to: Customize a Built-in Property Editor (ASP.NET) for details.

                                • Yuriy Khudz 11.13.2019

                                  But Xaf denies using ASPxIntPropertyEditor descendant  in inline edit...

                                • Anatol (DevExpress Support) 11.13.2019

                                  It should work unless the ListView's InlineEditMode is not Batch. If it is Batch, neither of the previously suggested approaches will help, since the Batch Edit mode does not use Property Editors. In this case, customize the grid column's GridViewDataSpinEditColumn.PropertiesSpinEdit according to the ASPxGridView documentation. To access grid columns, use the following approach: Access Grid Control Properties.

                                • Yuriy Khudz 11.14.2019

                                  My apologies, I was mistaken.
                                  The overriding of method CreateRestrictions fixed my problem and it works fine in inline edit. Thanks.
                                  May I ask you another tiny question: why this fix couldn't be included in XAF by default?

                                • Anatol (DevExpress Support) 11.14.2019

                                  Please describe your idea in greater detail. What fix do you mean?

                                • Yuriy Khudz 11.14.2019

                                  I mean the same behavior of editors for int and decimal.  

                                • Anatol (DevExpress Support) 11.14.2019

                                  Thank you for your feedback. Although there is always room for improvement, we do not have immediate plans to change the current MinValue and MaxValue implementation.