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

2 posts, 0 answers
  1. SethSpearman
    SethSpearman avatar
    4 posts
    Member since:
    Apr 2007

    Posted 24 Sep 2009 Link to this post

    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
  2. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 30 Sep 2009 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top