Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
c# how to see ListBox selected Item row number?

What I have tried:

c# how to see ListBox selected Item row number?
Posted
Updated 3-Mar-23 1:50am
Comments
Richard MacCutchan 3-Mar-23 7:28am    
Probably by writing some code to show the details.
Richard Deeming 3-Mar-23 7:33am    
Since you can't be bothered to tell us which of the 50+ different "listbox" controls you're using, nor which UI framework, let alone explain what you have tried and where you are stuck, nobody can help you.

Stop trying to type as little as possible. If you're typing the same thing in the title, the body, and the "what have you tried" box, then your question would be better answered by pasting it into Google.

1 solution

From your other questions, it's likely you are using a WinForms listbox - in which case just use the SelectedIndex (or SelectedIndices) property of the Listbox.

Do note that this refers to the order as displayed in the ListBox, not the order in which it was presented if you are using any form of databinding: A DataTable or a Collection for example. To find the index for that, you would need to search the original data source for the SelectedItem manually.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900