SpinEditor DataSource

3 posts, 1 answers
  1. Luis
    Luis avatar
    4 posts
    Member since:
    Apr 2016

    Posted 03 May Link to this post

    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. Luis
    Luis avatar
    4 posts
    Member since:
    Apr 2016

    Posted 03 May in reply to Luis Link to this post

    I know i can assign the value manually( the way numeric up down in regular WinForms works).
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Answer
    Dess
    Admin
    Dess avatar
    1609 posts

    Posted 05 May Link to this post

    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 at 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.
Back to Top