Results 1 to 9 of 9

Thread: Listview question

  1. #1

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    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]

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    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

  3. #3
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Question

    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.

  4. #4
    Guest
    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

  5. #5
    Guest
    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.

  6. #6
    Guest
    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

  7. #7
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    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

  8. #8
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Thumbs up Thanks ....

    Megatron, it did.

  9. #9

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    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
  •  



Click Here to Expand Forum to Full Width