Unplanned
Last Updated: 07 Apr 2016 08:11 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 17 Jul 2015 08:57
Category:
Type: Bug Report
1
FIX. RadDropDownListElement - simple data binding does not work for the SelectedValue property
To reproduce:

1. Add a RadRibbonBar with one tab and a RadRibbonBarButtonGroup.
2. Add a RadDropDownListElement in the RadRibbonBarButtonGroup and use the following code snippet:

DataTable dt = new DataTable();
Student student = new Student(123, "John Peterson", "B");

public Form1()
{
    InitializeComponent();

    this.radLabel1.Text = "Student's Id: " + student.Id.ToString();
   
    dt.Columns.Add("Id");
    dt.Columns.Add("Name");    
    dt.Rows.Add(1, "Student1");
    dt.Rows.Add(2, "Student2");
    dt.Rows.Add(3, "Student3");
   
    student.PropertyChanged += student_PropertyChanged;
    this.radDropDownListElement1.BindingContext = new BindingContext();
    this.radDropDownListElement1.DataSource = dt;
    this.radDropDownListElement1.DisplayMember = "Name";
    this.radDropDownListElement1.ValueMember = "Id";
    this.radDropDownListElement1.DataBindings.Add("SelectedValue", student, "Id", true, DataSourceUpdateMode.OnPropertyChanged);
}

private void student_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
    if (e.PropertyName == "Id")
    {
        this.radLabel1.Text = "Student's Id: " + student.Id.ToString();
    }
}

public class Student : System.ComponentModel.INotifyPropertyChanged
{
    int m_id;
    string m_name;
    string m_grade;

    public event PropertyChangedEventHandler PropertyChanged;

    public Student(int m_id, string m_name, string m_grade)
    {
        this.m_id = m_id;
        this.m_name = m_name;
        this.m_grade = m_grade;
    }

    public int Id
    {
        get
        {
            return m_id;
        }
        set
        {
            if (this.m_id != value)
            {
                this.m_id = value;
                OnPropertyChanged("Id");                   
            }
        }
    }

    public string Name
    {
        get
        {
            return m_name;
        }
        set
        {
            if (this.m_name != value)
            {
                this.m_name = value;
                OnPropertyChanged("Name");
            }
        }
    }

    public string Grade
    {
        get
        {
            return m_grade;
        }
        set
        {
            if (this.m_grade != value)
            {
                this.m_grade = value;
                OnPropertyChanged("Grade");
            }
        }
    }

    protected virtual void OnPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

3. If you change the selection in RadDropDownListElement you will notice that the Student.Id property is not affected. 

Note: this scenario works correctly with RadDropDownList control!

Workaround: use a RadHostItem and use RadDropDownList:

RadDropDownList ddl = new RadDropDownList();
ddl.MinimumSize = new System.Drawing.Size(100, 20);
RadHostItem host = new RadHostItem(ddl);
host.MinSize = new Size(100, 20);
this.radRibbonBarButtonGroup1.Items.Add(host);
ddl.DataSource = dt;
ddl.DisplayMember = "Name";
ddl.ValueMember = "Id";
ddl.DataBindings.Add("SelectedValue", student, "Id", true, DataSourceUpdateMode.OnPropertyChanged);

0 comments