Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Restrict Values Being Entered in Editors

The following sample code prohibits values greater than 100 being entered into the spin editor. The RepositoryItem.Validating event is handled to check the entered value’s validity. The BaseEdit.InvalidValue event is handled to display an exception hint if an invalid value has been entered.

BaseEdit.InvalidValue

using System.ComponentModel;
using DevExpress.XtraEditors.Controls;

private void spinEdit1_Validating(object sender, CancelEventArgs e) {
   if((sender as SpinEdit).Value >= 100)
      e.Cancel = true;
}
private void spinEdit1_InvalidValue(object sender, InvalidValueExceptionEventArgs e) {
   e.ErrorText = "The value should be less than 100";
}