This is a migrated thread and some comments may be shown as answers.

SpinEditor DataSource

2 Answers 70 Views
SpinEditor
This is a migrated thread and some comments may be shown as answers.
Luis
Top achievements
Rank 2
Luis asked on 03 May 2016, 03:22 PM

Hello there!

 

The function of the control itself it's pretty straightforward, however, it seems that it does not have the ability of binding to a data source. Is there any possible workaround?.

Thanks in advance.

2 Answers, 1 is accepted

Sort by
0
Luis
Top achievements
Rank 2
answered on 03 May 2016, 03:26 PM
I know i can assign the value manually( the way numeric up down in regular WinForms works).
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 05 May 2016, 12:24 PM
Hello Luis,

Thank you for writing.

In order to bind RadSpinEditor, you can use simple data binding. Here is a sample code snippet which result is illustrated the attached gif file: 
Product p;
Random rand = new Random();
 
public Form1()
{
    InitializeComponent();
    p = new Product(123, "Orange", 12.45m);
    this.radLabel1.Text = p.ToString();
    this.radSpinEditor1.DecimalPlaces = 2;
    this.radSpinEditor1.DataBindings.Add("Value", p, "Price", true, DataSourceUpdateMode.OnPropertyChanged);
}
 
private void radButton1_Click(object sender, EventArgs e)
{
    p.Price = rand.Next(0, 20) * 0.45m;
    this.radLabel1.Text = p.ToString();
}
 
public class Product: System.ComponentModel.INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
 
    protected virtual void OnPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
     
    private int _id;
    private string _name;
    private decimal _price;
     
    public int Id
    {
        get
        {
            return _id;
        }
        set
        {
            if (this._id != value)
            {
                this._id = value;
                OnPropertyChanged("Id");
            }
        }
    }
 
    public string Name
    {
        get
        {
            return _name;
        }
        set
        {
            if (this._name != value)
            {
                this._name = value;
                OnPropertyChanged("Name");
            }
        }
    }
 
    public decimal Price
    {
        get
        {
            return _price;
        }
        set
        {
            if (this._price != value)
            {
                this._price = value;
                OnPropertyChanged("Price");
            }
        }
    }
 
    public Product(int id, string name, decimal price)
    {
        this.Id = id;
        this.Name = name;
        this.Price = price;
    }
 
    public override string ToString()
    {
        return "Name: " + this.Name + " Price: " + this.Price;
    }
}

I hope this information helps. Should you have further questions I would be glad to help.

  Regards,
Dess
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
SpinEditor
Asked by
Luis
Top achievements
Rank 2
Answers by
Luis
Top achievements
Rank 2
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or