New to Telerik UI for WinForms? Download free 30-day trial

Null Value Support

Since R1 2017 RadSpinEditor supports null value. In order to enable this functionality it is necessary to set the EnableNullValueInput property to true. Thus, when the text is cleared and RadSpinEditor looses focus, null value will be set. The default Value property is of type int and it cannot be set to null. A new property,called NullableValue, is introduced for this purpose and it can be set to null. The NullableValueChanged event is fired when the NullableValue property is changed.

Simple Data Binding

You can find below a sample code snippet demonstrating how to use the NullableValue property with simple data binding:

Simple data binding with null value

public void InitializeNullableSpinEditor()
{ 

    this.radSpinEditor1.EnableNullValueInput = true;
    this.radSpinEditor1.NullableValueChanged += radSpinEditor1_NullableValueChanged;
    Item item = new Item("Apple", 2);
    this.radSpinEditor1.DataBindings.Add("NullableValue", item, "Id", true, DataSourceUpdateMode.OnPropertyChanged);
}
private void radSpinEditor1_NullableValueChanged(object sender, EventArgs e)
{
    RadMessageBox.Show("NullableValue is changed "+ this.radSpinEditor1.NullableValue);
}
public class Item : System.ComponentModel.INotifyPropertyChanged
{
    private string _name;
    private int? _id;
    public Item(string name, int? id)
    {
        this._name = name;
        this._id = id;
    }
    public string Name
    {
        get
        {
            return this._name;
        }
        set
        {
            this._name = value;
            OnPropertyChanged("Name");
        }
    }
    public int? Id
    {
        get
        {
            return this._id;
        }
        set
        {
            this._id = value;
            OnPropertyChanged("Id");
        }
    }
    public event PropertyChangedEventHandler PropertyChanged;
    protected virtual void OnPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}