Home / Community & Support / Knowledge Base / RadControls for WinForms / ComboBox and ListBox / Adding items programmatically to RadListBox

Adding items programmatically to RadListBox

Article Info

Rating: 2

Article information

Article relates to

RadListBox for WinForms

Created by

Georgi Stoyanov, Telerik

Last modified

June 30, 2008

Last modified by

Georgi Stoyanov, Telerik

HOW-TO
Add items programmatically to RadListBox

SOLUTION
This could be done using the Add method of Items collection. The important thing is that the Items collection is a collection of objects of type RadItem and in the case below - objects of type RadListBoxItem. You should always use descendant objects of type RadItem when you work with Items collection .Since RadItem class is designed as a base class instances of this type have no visual presentation and will not appear even when added to the collection. 

Here is a code snippet that should help you with this:

RadListBoxItem test1 = new RadListBoxItem("item 1");
radListBox1.Items.Add(test1);


Note: There are several constructors of RadListBoxItem with different parameters. In this case, the constructor takes as parameter the text of the new item which is then shown in the listbox.

For more information, please review the C#/VB code that comes with our examples (installed with RadControls for WinForms).

Comments

  • pablo , May 29, 2008

    I cannot insert an item to a radlistbox for code in vb, they can shake hands me?

  • Telerik Admin , Jun 30, 2008

    It is very important to note that RadItem class is designed as a base class for all visual items (please take a look at: http://www.telerik.com/help/winforms/architecture_tpfhierarchyraditem.html). Instances of this clas have no visible presentation and will not appear in the listbox.

If you'd like to comment on this KB article, please, send us a Support Ticket.
Thank you!

Please Sign In to rate this article.