|
-
May 11th, 2007, 04:45 PM
#1
Thread Starter
Fanatic Member
[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.
-
May 11th, 2007, 04:54 PM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
May 11th, 2007, 05:00 PM
#3
Thread Starter
Fanatic Member
Re: Listview Information
Will It Work For A ListBox?
-
May 11th, 2007, 05:04 PM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
May 11th, 2007, 05:12 PM
#5
Thread Starter
Fanatic Member
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?
-
May 11th, 2007, 05:46 PM
#6
Re: Listview Information
Use the ListCount property. Also, the Index for Listboxes is 0 based.
For i = 0 To Me.List1.ListCount - 1
-
May 11th, 2007, 05:49 PM
#7
Thread Starter
Fanatic Member
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.
-
May 11th, 2007, 09:14 PM
#8
Thread Starter
Fanatic Member
Re: Listview Information
When I Try To Run The Program I Get And Error That Says:
Invaild Qualifer
Then It Higlight This Word:
Of This Line:
Code:
If Me.List1.List(i).Selected = True Then
Anyone Know Why?
-
May 11th, 2007, 11:04 PM
#9
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!
-
May 11th, 2007, 11:09 PM
#10
Thread Starter
Fanatic Member
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?
-
May 12th, 2007, 01:03 AM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|