I know this topic has been discussed here quite often, but I can't get it to work and because they were written a long time ago maybe there are new informations for this.
My target is to add Objects in a RadComboBox or RadListBox (maybe it's supported now).
The first step is to bind a List<Object> to the Controls DataSource, then I fill the List but nothing is drawn/added to the control. If have checked both counts (ComboBox and List), ComboBox is 0 und List not. What is the reason?
Next thing I don't know exactly, is how to get the selected Objects. Im using a workaround by getting the Index of the Item and then getting the real Object from the list using the index. Is this correct or should I use another way?
Maybe someone can give me a solution for this, how to work with ComboBoxes and ListBoxes with my own Objects.
Thanks for your help,
regards
Juergen
5 Answers, 1 is accepted
Adding your object to a simple List<> will never reflect in the controls because this class does not support change notification or more concretely, it does not have the ListChanged event. You have to use BindingList<> instead.
In order to get the indices of the selected items you simply need to use the SelectedItems property. It is a collection and contains RadListBoxItem instances. Each RadListBoxItem has an Index property. Keep in mind however that this index is local to the collection, it is not the same as the index of the objects in your binding list. For example if RadListBox is sorted, the indices will not match.
I hope this information is useful.
Please write again if you have other questions.
Regards,Victor
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
thanks for your fast reply. It is working almost fine now. My issue now is, I'm having more dann 29000 objects in the listbox and when I clear the gui stucks. It has the same affect, as I set the DataSource to null.
Can you give me a hint how to get my object from the listbox without using indexes, so I can be sure it's the one which is selected.
Best regards
Juergen
I am afraid that setting the DataSource to null is slow because RadComboBox and RadListBox do not support true virtualization. They create internal objects for each item in the data source and these objects are being disposed and cleared from the collections that the controls maintain internally. We have plans to provide a completely new list box and combo box controls for Q2 2010 which will solve these performance issues. Q2 is due in mid summer.
You can get the real index through the DataItem property of RadComboBoxItem. You need to cast the DataItem property to the real type of your data source objects and use it to obtain an index from the BindingList. For example:
RadComboBoxItem item =
this
.radComboBox1.SelectedItem
as
RadComboBoxItem;
SomeDataObject dataObject = item.DataItem
as
SomeDataObject;
int
index = myBindingList.IndexOf(dataObject);
Write again if you have other questions. Best wishes,
Victor
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
So we have to wait for Q2, maybe we can handle this another way.
Thanks for the snippet, I have included it in my code and it's working fine.
I have just one other question, but I think it not fits to this section: Do you support NumericUpDowns ?
Regards,
Juergen
We have a separate numeric up-down control, it is called RadSpinEditor. RadComboBox cannot behave as a numeric up-down if this is what you meant.
Please write again if you have other questions.
Victor
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.