|
-
Aug 5th, 2000, 07:52 AM
#1
Thread Starter
Hyperactive Member
Hi,
I have a timer control and a listview control on my form. I want to go thorugh all the items in the listview control one by one at an interval of 1 second. how do i do that?
I was able to do that with a listbox control
Private Sub Timer1_Timer()
List1.ListIndex = List1.ListIndex + 1
End Sub
[Edited by wasiq on 08-05-2000 at 08:55 AM]
-
Aug 5th, 2000, 11:58 AM
#2
_______
<?>
Code:
'loop through a listview and display the items
'in the caption of a label
Option Explicit
Public i
Private Sub Command1_Click()
i = 1
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Timer1.Interval = 1000
Label1.Caption = ListView1.ListItems(i).Text
i = i + 1
If i = ListView1.ListItems.Count Then
Timer1.Enabled = False
End If
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Aug 5th, 2000, 01:07 PM
#3
Fanatic Member
Hi.
Of course, HeSaidJoe's code works, but I was trying to get each item in the ListView to be highlighted or selected just as this code:
Private Sub Timer1_Timer()
List1.ListIndex = List1.ListIndex + 1
End Sub
highlights each List Box Item as it cycles through. Is it possible to do this with the ListView Control? I couldn't get it to work.
-
Aug 5th, 2000, 01:24 PM
#4
HeSaidJoe: I would try to avoid Public variables as much as possible. You can declare a static variable instead.
OneSource: This should answer your question as well.
Code:
Private Sub Timer1_Timer()
Static I As Integer
If ListView1.ListItems(1).Selected = True Then I = 1
I = I + 1
If I = ListView1.ListItems.Count Then Timer1.Enabled = False
ListView1.ListItems(I).Selected = True
Print ListView1.SelectedItem
End Sub
-
Aug 5th, 2000, 01:55 PM
#5
For that List1.ListIndex = List1.ListIndex + 1, there should be an On Error Resume Next because when it gets to the end, it can't + 1 anymore, so it errors. That is, if you want the list to be selected.
-
Aug 5th, 2000, 02:22 PM
#6
I prefer to use Error Handling as a last resort. In this case, you can try a different approach.
Code:
List1.ListIndex = List1.ListIndex + 1
If List1.Selected(List1.ListCount - 1) = True Then Timer1.Enabled = False
-
Aug 5th, 2000, 02:26 PM
#7
_______
<?>
Sorry wsiq...got thrown for a loop by your question:
I want to go through all the items in the listview control one by one at an interval of 1 second. how do i do that?
Megatron:
Yes you are quite right..even MSDN suggest that you never ever use Public/Global varialbles except when absolutely necessary (absolutely no other way)as they are very hard to control and track.
Old habits die hard.
Code:
For i = 1 to 1000
Print [:D]"I will remember!"[:D]
Next i
Later.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Aug 5th, 2000, 03:56 PM
#8
Fanatic Member
Thanks ....
-
Aug 5th, 2000, 10:09 PM
#9
Thread Starter
Hyperactive Member
thank u people,
your source worked fine. I was able to highlight every selected item by using the following code.
Private Sub Command1_Click()
Static i As Integer
i = i + 1
ListView1.ListItems(i).Selected = True
ListView1.SetFocus
Label1.Caption = ListView1.SelectedItem
If i = ListView1.ListItems.Count Then i = 1
End Sub
Private Sub Form_Load()
For i = 0 To 100
ListView1.ListItems.Add , , i
Next i
End Sub
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
|