(RESOLVED)when vb listboox1.selecteditem hits the last item listbox1.selectedindex=0
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
If ListBox1.SelectedIndex = (last item) Then
Me.ListBox1.SelectedIndex = 0
End If
End Sub
Re: when vb listboox1.selecteditem hits the last item listbox1.selectedindex=0
Is that really a good idea? That means that you will never be able to select the last item.
Re: when vb listboox1.selecteditem hits the last item listbox1.selectedindex=0
This is the time when you type words in order to make your post understandable, posting code (without code tags) and hoping that your title is sufficient, often is not.
What you "appear" to be asking, is that when the user selects the last item in the listbox, that you actually select the first item. This would mean that your user can never select the last entry. Is this what you want? I can only guess what you are trying to do is create a roll-over method?
The first place you should check is the documentation, which has a list of all the properties of a listbox control, of which one is items, which has a count property. As the Index is 0 based, you would have to -1 from the value.
Code:
ListBox1.Items.Count -1
Re: when vb listboox1.selecteditem hits the last item listbox1.selectedindex=0
Quote:
Originally Posted by
Grimfort
This is the time when you type words in order to make your post understandable, posting code (without code tags) and hoping that your title is sufficient, often is not.
What you "appear" to be asking, is that when the user selects the last item in the listbox, that you actually select the first item. This would mean that your user can never select the last entry. Is this what you want? I can only guess what you are trying to do is create a roll-over method?
The first place you should check is the
documentation, which has a list of all the properties of a listbox control, of which one is items, which has a count property. As the Index is 0 based, you would have to -1 from the value.
Code:
ListBox1.Items.Count -1
i didnt have the right words to explain what i was trying to say and i always google and check msdn before i post i cant find most of the stuff im looking for there so i post here
ty
Re: when vb listboox1.selecteditem hits the last item listbox1.selectedindex=0
Quote:
Originally Posted by
jmcilhinney
Is that really a good idea? That means that you will never be able to select the last item.
i just made the last line a bunch of Os
Re: when vb listboox1.selecteditem hits the last item listbox1.selectedindex=0
Thats fair enough, however I found the answer using your own words in your first post. You can use a question in google, for example 'vb.net last item in a listbox' and the 7th item down was this (how can i get to the last item in a listbox). I am not trying to tell you off, more explain where to look to help you get answers yourself first, apologies if it did not come across that way.
Re: when vb listboox1.selecteditem hits the last item listbox1.selectedindex=0
Quote:
Originally Posted by
TD5X
i just made the last line a bunch of Os
Sounds like a hack to me.
Re: when vb listboox1.selecteditem hits the last item listbox1.selectedindex=0
I have supplied the line to test if you are at the last item, so you should now be able to get your code working. As already highlighted, there may be another way to do what you are trying to achieve, all we need is for you to tell us if you want advice :).
Re: when vb listboox1.selecteditem hits the last item listbox1.selectedindex=0
Quote:
Originally Posted by
Grimfort
I have supplied the line to test if you are at the last item, so you should now be able to get your code working. As already highlighted, there may be another way to do what you are trying to achieve, all we need is for you to tell us if you want advice :).
had to change it up a little but everything works well :]
Dim s1234 As String
s1234 = ListBox1.Items.Count - 1
thanks for the example
Re: when vb listboox1.selecteditem hits the last item listbox1.selectedindex=0
Quote:
Originally Posted by
jmcilhinney
Sounds like a hack to me.
depends what your definition of hacking is :afrog:
Re: when vb listboox1.selecteditem hits the last item listbox1.selectedindex=0
Given that Count is an Integer, therefore (Count - 1) is an Integer, why are you declaring 's1234' as type String? Also, why use a silly name like 's1234' when you can use a meaningful name like 'itemCount'?
Re: when vb listboox1.selecteditem hits the last item listbox1.selectedindex=0
Quote:
Originally Posted by
TD5X
depends what your definition of hacking is :afrog:
The definition I'm currently employing is using a dodgy workaround to do something that you shouldn't really be doing in the first place.
Re: when vb listboox1.selecteditem hits the last item listbox1.selectedindex=0
Quote:
Originally Posted by
jmcilhinney
Given that Count is an Integer, therefore (Count - 1) is an Integer, why are you declaring 's1234' as type String? Also, why use a silly name like 's1234' when you can use a meaningful name like 'itemCount'?
i was using s1234 as an example it works so im going to keep it that way and -1 doesnt work i had to use 0 like i was told by mr fox
Re: when vb listboox1.selecteditem hits the last item listbox1.selectedindex=0
Quote:
Originally Posted by
jmcilhinney
The definition I'm currently employing is using a dodgy workaround to do something that you shouldn't really be doing in the first place.
well then i am not hacking