SelectedValue not set to null

3 posts, 0 answers
  1. AungKo
    AungKo avatar
    14 posts
    Member since:
    Feb 2017

    Posted 26 Oct Link to this post

    I used BindingList for data binding,

    BindingList<Person> personList = new BindingList<Person>();
    radMultiColumnComboBox1.DataSource = personList;

     

    RadMultiColumnComboBoxElement multiColumnComboElement = this.radMultiColumnComboBox1.MultiColumnComboBoxElement;

    multiColumnComboElement.EditorControl.MasterTemplate.AutoGenerateColumns = false;

    GridViewTextBoxColumn column = new GridViewTextBoxColumn(); 
    column.HeaderText = "ID";

    column.FieldName = "id";

    column.Name = "colId";
    multiColumnComboElement.Columns.Add(column); 
    column = new GridViewTextBoxColumn(); 
    column.HeaderText = "Name";
    column.FieldName = "name";
    column.Name = "colName";
    multiColumnComboElement.Columns.Add(column); 

    Let Person object have two properties, id and name. I set ValueMember to id and DisplayMember to name.

    And I set the SelectedValue,

    radMultiColumnComboBox1.SelectedValue = person.id;

    This is working correctly. But when person.id become null, SelectedValue is not null, instead it select first item of BindingList<Person>.

    I can't understand why. Pls answer to me.

     

     

  2. Dess
    Admin
    Dess avatar
    2222 posts

    Posted 30 Oct Link to this post

    Hello, AungKo,

    Thank you for writing.  

    Firstly, I would like to note that it is important to set the AutoGenerateColumns property to false before setting the DataSource property. Otherwise, you will have duplicated columns.

    As to the question about the SelectedValue property, note that it will be set to the valid value considering the specified ValueMember. If you set the SelectedValue property to a value that is not present in the DataSource it won't be changed at all. That is why if you need to clear the selection, set the RadMultiColumnComboBox.SelectedIndex property to -1. I have attached a sample project for your reference.

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

    Regards,
    Dess
    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.
  3. AungKo
    AungKo avatar
    14 posts
    Member since:
    Feb 2017

    Posted 04 Nov Link to this post

    Thanks Dess. I got it.
Back to Top