Sorry for the confusing title but here is my situation: When I select an item from a listbox I want a label showing that item's number. For example if I choose the fifth item in the listbox the label should show "Item number 5 is selected".
How do I do this?
This is simple. All you need to do to get the index of the selected item in the listbox is to use the SelectedIndex property which returns the zero-based index of the selected item. If you want a one-based index instead, just add 1 to the index.
int index = listBox.SelectedIndex;
label.Text = $"Item number {index + 1} is selected.";
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments