Page 1 of 1

Listbox Counting help

Posted: Mon Sep 03, 2012 4:49 am
by 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

Re: Listbox Counting help

Posted: Mon Sep 03, 2012 7:37 am
by 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)

Re: Listbox Counting help

Posted: Tue Sep 04, 2012 7:00 am
by 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

Re: Listbox Counting help

Posted: Tue Sep 04, 2012 3:02 pm
by Filip
Try
Code: Select all
Dim Item As String = ListBox1.Items(no - 1).ToString

Re: Listbox Counting help

Posted: Tue Sep 04, 2012 9:03 pm
by 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