Generated ListBox Items

solus

Freshman
Joined
Apr 5, 2003
Location
Phoenix
I've got a ListBox that has its Items automatically generated. It basically adds all the items in a directory:

C#:
for (int i=0; i<sArray.Count; i++)
{
	this.LocalList.Items.Add(sArray[i].ToString());
}

How can I squeeze an EventHandler in there to each added item?
 
Last edited:

Volte

Neutiquam Erro
Joined
Nov 17, 2002
In the IDE code window use the top-left combo to select the ListBox
control, and the right combo to select the event. You can choose
the SelectIndexChanged event, for example, to find which item was
clicked:
Visual Basic:
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    MessageBox.Show("You chose item #" & ListBox1.SelectedIndex + 1)
End Sub
 

divil

Ultimate Contributor
Joined
Nov 17, 2002
Location
England
Since he's using C#, he'll have to select the listbox in the designer, switch to the Events tab in the propertygrid and doubleclick the event he needs to generate the wireup and handling code.
 
Top Bottom