tags:

views:

29

answers:

1

when i select list box items(multiple items) how i can display them.please help me

A: 

First, you need to set the SelectionMode property on your ListBox to either SelectionMode.MultiSimple or SelectionMode.MultiExtended (so that you can select multiple items).

Next, you need to add an event handler for the SelectedIndexChanged event on your ListBox. Within this event handler, accessing the SelectedItems collection of your ListBox will provide you with access to a collection of all the selected objects.

From there, you can iterate through the collection to display the objects in any manner you choose. Here's an example event handler that displays the selected items in a TextBox called textBox1:

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
   textBox1.Clear();
   foreach (object selectedItem in listBox1.SelectedItems)
   {
      textBox1.AppendText(selectedItem.ToString() + Environment.NewLine);
   }
}
Donut