Hi David,
Thank you for reporting this. This exception comes from the RadSpinEditor property used for numeric values. When the minimum value of the RadSpinEditor is set to a value bigger than 0, removing the last item in the bound collection will bring back the Value of the editor to 0. However, as the minimum property is set to 1 it will throw an exception. As a workaround, we can try to reset the Minimum property of the RadSpinEditor used in the control for numeric properties when the last item in the bound collection is removed.
public partial class RadForm1 : Telerik.WinControls.UI.RadForm
{
public RadForm1()
{
InitializeComponent();
this.radDataEntry1.EditorInitializing += RadDataEntry1_EditorInitializing;
List<TestClass> list = new List<TestClass>();
this.bindingSource1.DataSource = list;
this.radDataEntry1.DataSource = this.bindingSource1;
this.radBindingNavigator1.BindingSource = this.bindingSource1;
this.radBindingNavigator1.BindingNavigatorElement.DeleteButton.MouseDown += DeleteButton_MouseDown;
this.radBindingNavigator1.BindingNavigatorElement.AddNewButton.MouseDown += AddNewButton_MouseDown;
}
private void AddNewButton_MouseDown(object sender, MouseEventArgs e)
{
if ((this.bindingSource1.DataSource as List<TestClass>).Count == 0)
{
editor.Minimum = 1;
}
}
private void DeleteButton_MouseDown(object sender, MouseEventArgs e)
{
if ((this.bindingSource1.DataSource as List<TestClass>).Count == 1)
{
editor.Minimum = 0;
}
}
RadSpinEditor editor = new RadSpinEditor();
private void RadDataEntry1_EditorInitializing(object sender, EditorInitializingEventArgs e)
{
if (e.Editor is RadSpinEditor spinEditor)
{
editor = spinEditor;
}
}
}
In the above scenario, the TestClass contains 1 property with RadRange attribute which sets the minimum to 1.
internal class TestClass
{
[RadRange(1, 8000)]
public int PacketSize { get; set; } = 512;
}
Regards,
Dinko | Tech Support Engineer
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.