Hirashi3630
Hirashi3630

Reputation: 15

c# listbox numerical order of items

Hello I'm searching throught internet for hours but still I can not find the answer. (or I just don't know how to ask)

I need a simple numerical order of items in listbox fe. I am adding every 3rd items to listbox from txt file. When I have this in txt file:

Acc 4
name4
pass4
Acc 5
name5
pass5

I'll add to listbox only Acc4 and Acc5

And now when I select some item in listbox I want to know which one is selected but I don't want fe.: Acc6 (is selected) but I want to know Acc6is 3nd one in listbox (then order is 2)

PS: sorry for my end and thx for help

Upvotes: 0

Views: 91

Answers (1)

Breian Wells
Breian Wells

Reputation: 111

If you are looking for the index of the selected item in a listbox try

{listBoxName}.SelectedIndex

This will give you the index (0 based) of a selected item. https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.listbox.selectedindex?view=netframework-4.7.2

If you want the item try

{listBoxName}.SelectedItem

This gives the currently selected item https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.listbox.selecteditem?view=netframework-4.7.2

Upvotes: 1

Related Questions