Adding Items to a ListBox

Sample code shows you how to add items to a list box.

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. }