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

ComboBox and ListBox Adding Objects

5 Answers 108 Views
ComboBox and ListBox (obsolete as of Q2 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Juergen Holzer
Top achievements
Rank 2
Juergen Holzer asked on 24 Mar 2010, 01:45 PM
Hello!

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

Sort by
0
Victor
Telerik team
answered on 24 Mar 2010, 04:17 PM
Hello Juergen Holzer,

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.
0
Juergen Holzer
Top achievements
Rank 2
answered on 25 Mar 2010, 12:16 PM
Hello,

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
0
Victor
Telerik team
answered on 25 Mar 2010, 06:23 PM
Hello Juergen Holzer,

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.
0
Juergen Holzer
Top achievements
Rank 2
answered on 25 Mar 2010, 06:51 PM
I even thought this will be the reason, but in my opinion creating objects and drawing them costs much more time, so I'm a bit confused about this behaviour.
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
0
Victor
Telerik team
answered on 29 Mar 2010, 02:04 PM
Hi Juergen Holzer,

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.
 

Greetings,
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.
Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
Juergen Holzer
Top achievements
Rank 2
Answers by
Victor
Telerik team
Juergen Holzer
Top achievements
Rank 2
Share this question
or