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

Can you get the object out of a bound Rad collection control

1 Answer 69 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.
SethSpearman
Top achievements
Rank 1
SethSpearman asked on 24 Sep 2009, 11:46 PM
Hello,

I hope that someone can help me with an issue related to binding a bindable collection class to one of the Winforms Telerik list controls.  

If you bind to a plain ole windows list control like this...

    dim list as new comboBox
    
    with list
        .DataSource=myCollectionClass  'this contains a collection of widgets.
        .ValueMember="WidgetID"
        .DisplayMember="WidgetName"
    end with

I can then get a widget out of the list by doing this...

    Dim myWidget as Widget=ctype(list.Items(0),Widget)

If you do the exact same code with for example a Telerik RadListBox (same example as above)
but change line one to be   

    Dim list as new RadComboBox.  

With RadControls it seems you cannot cast to the Object type directly.  Whenever I try this I get the following error...  

    Unable to cast object of type 'Telerik.WinControls.UI.RadListBoxItem'
    to type 'Widget'.

Can someone at the least confirm that this is a known limitation of Telerik RadControls for Winforms or let me know the proper way to do it.

Thanks.

Seth

1 Answer, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 30 Sep 2009, 11:10 AM
Hi SethSpearman,

You can take the data bound item by the DataItem property that RadComboBoxItem exposes. For example:
Me.Text = (CType((CType(Me.RadComboBox1.SelectedItem, RadComboBoxItem)).DataItem, Employee)).Phone 

If you have additional questions, feel free to contact me.

Best wishes,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
SethSpearman
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Share this question
or