Listbox - Error in Type Requirements for Items.Add()

2 posts, 1 answers
  1. Pawz
    Pawz avatar
    51 posts
    Member since:
    Aug 2007

    Posted 29 Jan 2008 Link to this post

    In the rad list box, the Items.Add() function requires a variable of the type 'RadItem'. However, the following code crashes, with a 'Cannot convert RadItem to RadListBoxItem' error:

                foreach(string s in args) 
                { 
                    RadItem item = new RadItem (); 
                    item.Text = s; 
                    radListBox1.Items.Add(item); 
                } 

    Changing it to a RadListBoxItem instead of the standard RadItem works.

    Just something to add to your todo list :)
  2. Answer
    Georgi
    Admin
    Georgi avatar
    212 posts

    Posted 01 Feb 2008 Link to this post

    Hi Pawz,

    Thank you for pointing this out for us. Indeed, adding anything but RadListBoxItem in the RadListBox.Items collection caused throwing such exception. We have already added refactored RadListBox (and respectively RadComboBox) to be capable of adding any descendants if RadItem. We will introduce this behavior in the upcoming Q3 2007 Service pack version, scheduled next week. Note that you will still not be able to add RadItem instances as this is a base class. Instead you should use descendants of this class.

    Feel free to contact us if you have other questions.

    Greetings,
    Georgi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top