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

Binding to RangeStart and RangeEnd of RadRangeSelector

1 Answer 101 Views
RangeSelector
This is a migrated thread and some comments may be shown as answers.
Czeshirecat
Top achievements
Rank 2
Iron
Iron
Czeshirecat asked on 27 Mar 2018, 01:51 PM

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));

 


1 Answer, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 28 Mar 2018, 10:37 AM
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.
Tags
RangeSelector
Asked by
Czeshirecat
Top achievements
Rank 2
Iron
Iron
Answers by
Hristo
Telerik team
Share this question
or