Binding to RangeStart and RangeEnd of RadRangeSelector

2 posts, 0 answers
  1. Czeshirecat
    Czeshirecat avatar
    66 posts
    Member since:
    Jun 2016

    Posted 27 Mar 2018 Link to this post

    My range selector represents the 100% length of a running track. RangeStart represents the position of the start line, RangeEnd is represents the end.

    I tried databinding to the RangeStart and RangeEnd properties of my selector but, after the initial binding get/set there didn't appear to be any further property change events when I changed the ranges.

    How do I bind please?

     

    radRangeSelector1.DataBindings.Add(new Binding(
      radRangeSelector1.GetMemberName(x => x.StartRange),
      bs, this.GetMemberName(x => x.StartRange),
      false, DataSourceUpdateMode.OnPropertyChanged));
    radRangeSelector1.DataBindings.Add(new Binding(
      radRangeSelector1.GetMemberName(x => x.EndRange),
      bs, this.GetMemberName(x => x.EndRange),
      false, DataSourceUpdateMode.OnPropertyChanged));

     


  2. Hristo
    Admin
    Hristo avatar
    1520 posts

    Posted 28 Mar 2018 Link to this post

    Hi Claire,

    Thank you for writing.

    The Winforms simple data binding mechanism relies on Changed events which must be raised from your data object. With that in mind, the data object must raise a PropertyNameChanged event with the name of the property or it must implement the INotifyPropertyChanged interface. Please check the following MSDN resource: https://docs.microsoft.com/en-us/dotnet/framework/winforms/change-notification-in-windows-forms-data-binding#change-notification-for-simple-binding.

    I tested a sample project and the StartRange and EndRange properties of the control were updated as soon as the data-bound properties in the model got changed: 
    public partial class Form1 : Form
    {
        RangeDataObject dataObject;
     
        public Form1()
        {
            InitializeComponent();
     
            this.dataObject = new RangeDataObject() { StartRange = 5, EndRange = 60};
            this.radRangeSelector1.DataBindings.Add(new Binding("StartRange", this.dataObject, "StartRange", false, DataSourceUpdateMode.OnPropertyChanged));
            this.radRangeSelector1.DataBindings.Add(new Binding("EndRange", this.dataObject, "EndRange", false, DataSourceUpdateMode.OnPropertyChanged));
        }
     
        private void button1_Click(object sender, EventArgs e)
        {
            this.dataObject.StartRange = 10;
            this.dataObject.EndRange = 80;
        }
    }
     
    public class RangeDataObject : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
     
        private float startRange;
        public float StartRange
        {
            get
            {
                return this.startRange;
            }
            set
            {
                if (this.startRange != value)
                {
                    this.startRange = value;
                    OnPropertyChanged("StartRange");
                }
            }
        }
     
        private float endRange;
        public float EndRange
        {
            get
            {
                return this.endRange;
            }
            set
            {
                if (this.endRange != value)
                {
                    this.endRange = value;
                    OnPropertyChanged("EndRange");
                }
            }
        }
     
        protected virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

    I hope this helps. Let me know if you have other questions.

    Regards,
    Hristo
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top