Export (0) Print
Expand All

How to: Add and Clear Items in a ListBox Control

Visual Studio 2008

This example adds the contents of a Windows Forms TextBox control to a ListBox control when you click button1, and clears the contents when you click button2.

private void button1_Click(object sender, System.EventArgs e)
{
    listBox1.Items.Add("Sally");
    listBox1.Items.Add("Craig");
}

private void button2_Click(object sender, System.EventArgs e)
{
    listBox1.Items.Clear();
}

This example requires:

  • A form with a ListBox control named listBox1 and two buttons named button1 and button2. Add the button1 Click event handler to button1_Click, and the button2 Click event handler to button2_Click.

Community Additions

ADD
Show:
© 2014 Microsoft