Listbox Counting help

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
5 posts Page 1 of 1
Contributors
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Listbox Counting help
muttley1968
hello I need to count through a listbox and make it select an item soo say I have 100 enteries in the listbox and I need to find what enterie number 34 is how would I make it work that out please I already have set up a system to predict the amount it needs to count and total amount of people in the listbox its self just need this bit done now :P
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

Re: Listbox Counting help
Filip
Code: Select all
    Function GetItemByID(ByVal no As Integer)
        Dim Item As String = ListBox1.Items(no - 1) 'Declares string item which is equal to item on no place in listbox (since index starts from 0 not from 1, no must be substracted by 1)'
        Return Item 'Returns Text on no place'
    End Function
calling:
Code: Select all
Textbox1.text = GetItemByID(12)
CodenStuff wrote:
Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Re: Listbox Counting help
muttley1968
I tired that and it says that it is not a valid index :( I also tried playing round with it and no matter what way I changed it + - whatever allways was not a valid index
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

Re: Listbox Counting help
Filip
Try
Code: Select all
Dim Item As String = ListBox1.Items(no - 1).ToString
CodenStuff wrote:
Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D
User avatar
M1z23R
VIP - Donator
VIP - Donator
Posts: 622
Joined: Tue Sep 28, 2010 4:55 pm

Re: Listbox Counting help
M1z23R
it is small stupid thing xD easily change it to
Code: Select all
dim str As string =listview1.items(number between 0 and itemcount-1 ).TEXT
edit: my bad didn't see it is listBOX...
Code: Select all
For i as integer =0 to listbox1.items.count - 1
if listbox1.items(i) = 34 then msgbox(i.tostring)
next
5 posts Page 1 of 1
Return to “Coding Help & Support”