-
Jul 22nd, 2014, 02:04 PM
#1
Thread Starter
Addicted Member
Navigating items on ListView with Horizontal Scroll Bar Control
Hello again everyone.
I'm having a rather simple problem, that's proving hard for me to understand a way to solve it...
I have a listview with a number of items and I'd like to select them one by one with the aid of a horizontal scroll bar control.
I've set the maximum and mininum values of the scroll bar like so:
vb.net Code:
hsbPlayListNavigator.Maximum = lvPlayList.Items.Count
hsbPlayListNavigator.Minimum = 0
Note: The lvPlayList is the ListView control I'm using to store the items.
Then I've got the following code for the Horizontal Scroll Bar scroll Event:
vb.net Code:
Private Sub hsbPlayListNavigator_Scroll(sender As Object, e As ScrollEventArgs) Handles hsbPlayListNavigator.Scroll
For i As Integer = 0 To lvPlayList.Items.Count - 1
If e.Type = ScrollEventType.SmallDecrement Then
ElseIf e.Type = ScrollEventType.SmallIncrement Then
ElseIf e.Type = ScrollEventType.First Then
ElseIf e.Type = ScrollEventType.Last Then
End If
Next
End Sub
And this is where I'm stuck, because I don't have a clue on how to check which item is selected and how to go to the next item on the ListView control.
There's no selecteditem property like on the ComboBox, so I'm not sure of what to do.
-
Jul 22nd, 2014, 02:25 PM
#2
Re: Navigating items on ListView with Horizontal Scroll Bar Control
which View do you use in your listview?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 22nd, 2014, 02:26 PM
#3
Re: Navigating items on ListView with Horizontal Scroll Bar Control
do you have MultiSelect set to False?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 22nd, 2014, 02:31 PM
#4
Thread Starter
Addicted Member
Re: Navigating items on ListView with Horizontal Scroll Bar Control
The property View is set to Details and yes I did set the MultiSelect property to false. Sorry, forgot to mention those x.x
-
Jul 22nd, 2014, 02:32 PM
#5
Re: Navigating items on ListView with Horizontal Scroll Bar Control
there is a selecteditems property and a selectedindices property.
if multiselect = false then listview.selectedindices(0) is the selectedindex
edit: but it'll cause an error if there is no selecteditem
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 22nd, 2014, 02:35 PM
#6
Re: Navigating items on ListView with Horizontal Scroll Bar Control
Hi,
I see that .paul. is going the same way I was thinking so assuming that the MultiSelect property of the ListView is false and so long as you set the Scroll bar values correctly then you don’t need to do any of that. The first thing to note is that the Maximum values of the scroll bar should be set to:-
vb.net Code:
hsbPlayListNavigator.Maximum = lvPlayList.Items.Count-1
Once done, you can simply say the following in the Scroll event of the Scroll Bar:-
vb.net Code:
With ListView1.Items(e.NewValue)
.Selected = True
.EnsureVisible()
End With
Hope that helps.
Cheers,
Ian
-
Jul 22nd, 2014, 03:57 PM
#7
Thread Starter
Addicted Member
Re: Navigating items on ListView with Horizontal Scroll Bar Control
Thanks everyone for the replies. I just got home from work and I'm dead tired... I'll sweep through your suggestions tomorrow and will come back with some feedback.
-
Jul 23rd, 2014, 03:30 AM
#8
Thread Starter
Addicted Member
Re: Navigating items on ListView with Horizontal Scroll Bar Control
I'm back again with some vb.net goodness lol.
IanRyder's code worked fine, I think.
I'm not able to select any of the items on the ListView, but the first one. I went on debugging the scroll event and it seems that the NewValue property is always set to 0. I noticed that the scroll bar box is filling the whole control, which means that the max property is implicetly set to 0 (at least I think that's where the problem is).
On debugging, I checked the max property value and it is set to 2, which is the current value of lvPlayList.Items.Count-1, so I'm not sure what the hell I'm missing.
Here's a screenshot to better describe what's happening:
Edit* Sorry about the image attachment. I don't know why the image is that small, on my computer it was saved at a larger size...
Last edited by Simbiose; Jul 23rd, 2014 at 03:43 AM.
-
Jul 23rd, 2014, 04:23 AM
#9
Re: Navigating items on ListView with Horizontal Scroll Bar Control
Hi,
IanRyder's code worked fine, I think.
Here are a couple of extra pointers for you:-
When using the ListView, if you select something in code and the control does not have the focus then the selection is hidden. This can be overcome by setting the property HideSelection to False and even then the highlight can be difficult to see so it is often best to set the property FullRowSelect to True and then move the focus back to the ListView control to show the highlight in full. i.e:-
vb.net Code:
With ListView1.Items(e.NewValue)
.Selected = True
.EnsureVisible()
End With
ListView1.Select()
I noticed that the scroll bar box is filling the whole control,
As to the Scroll bar filling the control here is something I did not know. As I have done, the first thing you should always do if you see unexpected results is to read the documentation for the properties and methods you are using. In this case have a read here:-
ScrollBar.Maximum Property
Can you see the issue? Once found, you will then need to compensate for the ListView Item Index when scrolling.
Hope that helps.
Cheers,
Ian
-
Jul 23rd, 2014, 06:08 AM
#10
Thread Starter
Addicted Member
Re: Navigating items on ListView with Horizontal Scroll Bar Control
Originally Posted by IanRyder
Hi,
Here are a couple of extra pointers for you:-
When using the ListView, if you select something in code and the control does not have the focus then the selection is hidden. This can be overcome by setting the property HideSelection to False and even then the highlight can be difficult to see so it is often best to set the property FullRowSelect to True and then move the focus back to the ListView control to show the highlight in full. i.e:-
vb.net Code:
With ListView1.Items(e.NewValue) .Selected = True .EnsureVisible() End With ListView1.Select()
As to the Scroll bar filling the control here is something I did not know. As I have done, the first thing you should always do if you see unexpected results is to read the documentation for the properties and methods you are using. In this case have a read here:-
ScrollBar.Maximum Property
Can you see the issue? Once found, you will then need to compensate for the ListView Item Index when scrolling.
Hope that helps.
Cheers,
Ian
Aaaaah, now I'm getting places
Thank you very much for the help, I am now able to select up 2 items, I'm still missing something, but I'm still trying to work it around.
I have the following code so far:
Initializers
vb.net Code:
lvPlayList.MultiSelect = False lvTotalPages = Math.Floor((lvPlayList.Items.Count - 1) / 13) + 1 hsbPlayListNavigator.Maximum = lvPlayList.Items.Count - 1 hsbPlayListNavigator.Minimum = 0 hsbPlayListNavigator.SmallChange = 1 hsbPlayListNavigator.LargeChange = (lvPlayList.Items.Count - 1) / lvTotalPages
Scroll Event
vb.net Code:
If e.Type = ScrollEventType.SmallDecrement Then With lvPlayList.Items(e.NewValue) .Selected = True .EnsureVisible() End With e.NewValue -= 1 ElseIf e.Type = ScrollEventType.SmallIncrement Then With lvPlayList.Items(e.NewValue) .Selected = True .EnsureVisible() End With e.NewValue += 1 ElseIf e.Type = ScrollEventType.First Then 'Still need to think what I need to do here ElseIf e.Type = ScrollEventType.Last Then 'Still need to think what I need to do here End If
Edit* Ok I got the scrollbar to scroll throughout every item on listview with the following code:
Initializers
vb.net Code:
lvPlayList.MultiSelect = False lvPlayList.MultiSelect = False lvTotalPages = Math.Floor((lvPlayList.Items.Count - 1) / 13) + 1 hsbPlayListNavigator.Maximum = lvPlayList.Items.Count - 1 hsbPlayListNavigator.Minimum = 0 hsbPlayListNavigator.SmallChange = 1 hsbPlayListNavigator.LargeChange = (hsbPlayListNavigator.Maximum - 1) / lvTotalPages
Scroll Event
vb.net Code:
If e.Type = ScrollEventType.SmallDecrement Then With lvPlayList.Items(e.NewValue) .Selected = True .EnsureVisible() End With ElseIf e.Type = ScrollEventType.SmallIncrement Then With lvPlayList.Items(e.NewValue) .Selected = True .EnsureVisible() End With ElseIf e.Type = ScrollEventType.First Then 'Still need to think what I need to do here ElseIf e.Type = ScrollEventType.Last Then 'Still need to think what I need to do here End If
However, there's something that doesn't feel right... by checking the following line of code:
vb.net Code:
hsbPlayListNavigator.LargeChange = (hsbPlayListNavigator.Maximum - 1) / lvTotalPages
I noticed that it's the same as having:
vb.net Code:
hsbPlayListNavigator.LargeChange = 1
So... if I set SmallChange and LargeChange properties to 1, the scrollbar box adjusts to the same size as the number of items on the ListView control and I'm trying to make some sense of it and the only conclusion I can reach is that when I set the Maximum property as the total number of items on the ListView and since my logic is to slide the scrollbar according to each item on the ListView control, it's safe to say that each click on the Scrollbar arrows is equivalent to 1 unit of width measurement of the scrollbar box?
I have a feeling that what I'm saying ins't easy to understand and I'm probably complicating things, but may anyone confirm if I'm right?
Last edited by Simbiose; Jul 23rd, 2014 at 06:58 AM.
-
Jul 23rd, 2014, 11:07 AM
#11
Thread Starter
Addicted Member
Re: Navigating items on ListView with Horizontal Scroll Bar Control
Hello, just pointing out that there's still a question in the air here :P
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
|