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

SelectedValue not set to null

1 Answer 224 Views
MultiColumn ComboBox
This is a migrated thread and some comments may be shown as answers.
Zan
Top achievements
Rank 1
Zan asked on 27 Oct 2017, 04:55 AM

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.

 

 

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 30 Oct 2017, 02:03 PM
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.
Zan
Top achievements
Rank 1
commented on 04 Nov 2017, 10:06 AM

Thanks Dess. I got it.
Roland
Top achievements
Rank 1
commented on 02 Jun 2021, 06:34 PM | edited

Moved question to WPF
Dess | Tech Support Engineer, Principal
Telerik team
commented on 03 Jun 2021, 06:01 AM

Hello, Roland,
 
I would like to note that this forum is related to the Telerik UI for WinForms suite. If you have any inquiries about the Telerik UI for WPF suite, feel free to post your questions in the relevant forum: https://www.telerik.com/forums/wpf 
Thus, the appropriate community will gladly assist you.

Thank you for your understanding.
Roland
Top achievements
Rank 1
commented on 03 Jun 2021, 12:12 PM

Thanks Dess - That's why I moved my question to the WPF forum (see my comment).
Dess | Tech Support Engineer, Principal
Telerik team
commented on 03 Jun 2021, 01:20 PM

Roland, I am not quite sure what do you mean with "moved my question to the WPF forum". However, our forum doesn't have any default functionality for moving a question from one product forum to another. If you need to ask the Telerik WPF community a question, it would be necessary to submit a forum thread in the previously referred WPF forum. 

If I missing anything, please provide some more details so I can understand better your point and provide any further assistance if possible. Thank you for your understanding.

Tags
MultiColumn ComboBox
Asked by
Zan
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or