Results 1 to 11 of 11

Thread: [Resolved] Listview Information

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Resolved [Resolved] Listview Information

    Ok I Have A List View Called skinlist and lets say i have an item in the listview called click me and i have a button called check. What's the code for when i press the check button it'll check to see if click me was selected and show a message box saying i selected click me.

    Thx
    Last edited by GDOG34; May 12th, 2007 at 02:36 AM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Listview Information

    You can use a loop checking the items for the .Selected property = true.

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
        Dim i As Integer
        For i = 1 To Me.ListView1.ListItems.Count
            If Me.ListView1.ListItems(i).Selected = True Then
                MsgBox Me.ListView1.ListItems(i).Text & " is selected"
            End If
        Next
    End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Re: Listview Information

    Will It Work For A ListBox?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Listview Information

    No you need to change it from Me.ListView1.ListItems to Me.List1.List
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Re: Listview Information

    Sorry With A List Box I Get Thos Error:

    Argument Not Optional

    Then It HighLights This Code:

    Private Sub Command1_Click()
    Dim i As Integer
    For i = 1 To Me.List1.List
    If Me.List1.List(i).Selected = True Then
    MsgBox Me.List1.List(i).Text & " is selected"
    End If
    Next
    End Sub

    Did I Rewrite This Correctly?

  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Listview Information

    Use the ListCount property. Also, the Index for Listboxes is 0 based.

    For i = 0 To Me.List1.ListCount - 1

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Re: Listview Information

    I Changed It And It Says Invaild Qualifer On This Line:
    Code:
    If Me.List1.List(i).Selected = True Then
    It HighLights The Word List.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Re: Listview Information

    When I Try To Run The Program I Get And Error That Says:

    Invaild Qualifer

    Then It Higlight This Word:

    Code:
    List
    Of This Line:
    Code:
    If Me.List1.List(i).Selected = True Then
    Anyone Know Why?

  9. #9
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: Listview Information

    Try this.

    Code:
    Option Explicit
    
    Private Sub Form_Load()
    Dim x As Long
    
    For x = 0 To 100
        List1.AddItem x
    Next
    End Sub
    
    
    Private Sub Command1_Click()
    If List1.ListIndex = -1 Then
        MsgBox "Please select from the list"
    Else
        MsgBox "I selected " & List1.Text
    End If
    End Sub
    Hope that helps!

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Re: Listview Information

    Thankyou, May I Ask This Haves 100 Strings And Less Say I Change It To 10 Can I Have It Do Something Different For Each One I Do? Lets Say If I Select 0 Then It Can Open Form1, Then If I Select 1 It Can Open Form2. Is That Possible?

  11. #11
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: Listview Information

    Yes you can.

    Code:
    Private Sub Command1_Click()
    Dim frm As Form
    
    If List1.ListIndex = -1 Then
        MsgBox "Please select from the list"
    Else
        Select Case List1.Text
           Case 2
              Form2.Show
           Case 3
              Form3.Show
           '... etc etc
           Case Else
              Exit Sub
        End Select
    End If
    End Sub
    Keeping it simple.

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