|
-
Mar 11th, 2011, 03:15 AM
#1
Thread Starter
Member
(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
Last edited by TD5X; Mar 16th, 2011 at 02:49 AM.
-
Mar 11th, 2011, 04:24 AM
#2
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.
-
Mar 11th, 2011, 04:30 AM
#3
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
-
Mar 11th, 2011, 04:49 AM
#4
Thread Starter
Member
Re: when vb listboox1.selecteditem hits the last item listbox1.selectedindex=0
 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
-
Mar 11th, 2011, 04:51 AM
#5
Thread Starter
Member
Re: when vb listboox1.selecteditem hits the last item listbox1.selectedindex=0
 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
-
Mar 11th, 2011, 05:00 AM
#6
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.
Last edited by Grimfort; Mar 11th, 2011 at 05:01 AM.
Reason: Dodgy spelling
-
Mar 11th, 2011, 05:54 AM
#7
Re: when vb listboox1.selecteditem hits the last item listbox1.selectedindex=0
 Originally Posted by TD5X
i just made the last line a bunch of Os
Sounds like a hack to me.
-
Mar 11th, 2011, 06:02 AM
#8
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 .
-
Mar 12th, 2011, 12:40 AM
#9
Thread Starter
Member
Re: when vb listboox1.selecteditem hits the last item listbox1.selectedindex=0
 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
-
Mar 12th, 2011, 12:42 AM
#10
Thread Starter
Member
Re: when vb listboox1.selecteditem hits the last item listbox1.selectedindex=0
 Originally Posted by jmcilhinney
Sounds like a hack to me.
depends what your definition of hacking is
-
Mar 12th, 2011, 12:43 AM
#11
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'?
-
Mar 12th, 2011, 12:44 AM
#12
Re: when vb listboox1.selecteditem hits the last item listbox1.selectedindex=0
 Originally Posted by TD5X
depends what your definition of hacking is 
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.
-
Mar 16th, 2011, 02:47 AM
#13
Thread Starter
Member
Re: when vb listboox1.selecteditem hits the last item listbox1.selectedindex=0
 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
-
Mar 16th, 2011, 02:48 AM
#14
Thread Starter
Member
Re: when vb listboox1.selecteditem hits the last item listbox1.selectedindex=0
 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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|