Adding Items to a ListBox

Ok, adding items to a listbox control is easy. You use Add method of the control. The following code shows you how to do so.
 
Drag a ListBox control on a form and use the following code to add items to the control.
 
 
 
Source Code
  1. private void Form1_Load(object sender, System.EventArgs e)  
  2. {  
  3.     string str = "First item";  
  4.     int i = 23;  
  5.     float flt = 34.98f;  
  6.     listBox1.Items.Add(str);  
  7.     listBox1.Items.Add(i.ToString());  
  8.     listBox1.Items.Add(flt.ToString());  
  9.     listBox1.Items.Add("Last Item in the List Box");  
  10. }  


Recommended Ebook

Printing in C# Made Easy

Download Now!
Similar Articles
Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.