Results 1 to 6 of 6

Thread: Help!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    249

    Unhappy Help!

    Okay, I have a Listview (with items) and I want it so that everytime i push a command button (Next Record button) it will select the next item/record in my Listview, as well as if i click the second command button (Previous Record button) then it will select the record before the one you are currently on...pretty much in general a Next and Previous buttons instead of manualy clicking each record...How do I do this?...Please Help - All code is welcome

    Thanks.

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Help!

    Try this:
    Code:
    Private Sub Command1_Click()    '~~~ Next button
        If ListView1.ListItems.Count <= 0 Then Exit Sub
        
        If ListView1.SelectedItem.Index = ListView1.ListItems.Count Then
            ListView1.ListItems(1).Selected = True
        Else
            ListView1.ListItems(ListView1.SelectedItem.Index + 1).Selected = True
        End If
        
    End Sub
    
    Private Sub Command2_Click()    '~~~ Previous button
        If ListView1.ListItems.Count <= 0 Then Exit Sub
        
        If ListView1.SelectedItem.Index = 1 Then 
            ListView1.ListItems(ListView1.ListItems.Count).Selected = True
        Else
            ListView1.ListItems(ListView1.SelectedItem.Index - 1).Selected = True
        End If
    End Sub
    Make sure to set the Hide Selection property of ListView to FALSE.
    ...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Help!

    Does your ListView only display one line at time?

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    249

    Re: Help!

    No, unfortunatly that code did not do anything, and what do you mean does it displayy one line at a time? its a listview with a whole lot of items/records.

  5. #5
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Help!

    Code:
    Private Sub cmdNext_Click()
       If (ListView1.ListItems.Count > 0) And (ListView1.SelectedItem.Index < ListView1.ListItems.Count) Then
          ListView1.ListItems.Item(ListView1.SelectedItem.Index + 1).Selected = True
       End If
    End Sub
    
    Private Sub cmdPrev_Click()
       If (ListView1.ListItems.Count > 0) And (ListView1.SelectedItem.Index > 1) Then
          ListView1.ListItems.Item(ListView1.SelectedItem.Index - 1).Selected = True
       End If
    End Sub
    Make sure HideSelection is not turned on in the ListView properties or you want see the selection marker.

  6. #6
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Help!

    Quote Originally Posted by anthony_pacitto3 View Post
    No, unfortunatly that code did not do anything, and what do you mean does it displayy one line at a time? its a listview with a whole lot of items/records.
    Then, tell us more details. If possible, try to include snapshots of what you want, etc.

    We don't know what you have in your mind..!
    ....

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

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