I have object names in a ListBox. When a name(line) is clicked, I need to know which line (by number) has been selected. Using that number, I can then do various operations including inserting text into 7 different text boxes. The line number would be the determining number for a switch/case operation. I am using a form setup in C#.
Novice3, Alan

Recommended Answers

All 3 Replies

Use the SelectedIndex property.

Just to add, remember that arrays are zero based so if you have five items in your list box and select the first item the SelectedIndex proeprty will return zero whereas the last item will return 4.

listBox.Item.SelectedItem for String and
istBox.SelectedIndex for Index.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.