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:

private void Form1_Load(object sender, System.EventArgs e)
{
string str = "First item";
int i = 23;
float flt = 34.98f;
listBox1.Items.Add(str);
listBox1.Items.Add(i.ToString());
listBox1.Items.Add(flt.ToString());
listBox1.Items.Add("Last Item in the List Box");
}

Up Next
    Ebook Download
    View all
    Learn
    View all