solus Posted April 9, 2003 Posted April 9, 2003 (edited) I've got a ListBox that has its Items automatically generated. It basically adds all the items in a directory: 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? Edited April 9, 2003 by solus Quote Can't afford to be neutral on a moving train...
Moderators Robby Posted April 9, 2003 Moderators Posted April 9, 2003 You can already pin-point the selected item using existing handlers, why do you want per item? Quote Visit...Bassic Software
solus Posted April 10, 2003 Author Posted April 10, 2003 Could you give me an example of these handlers? Or a reference to a page that gives an example? Quote Can't afford to be neutral on a moving train...
*Experts* Volte Posted April 10, 2003 *Experts* Posted April 10, 2003 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: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 Quote
*Gurus* divil Posted April 10, 2003 *Gurus* Posted April 10, 2003 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. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.