Solved

Listview what was last item ticked

Posted on 2004-08-03
6
348 Views
Last Modified: 2012-08-14
With the code below how can i find out the last item ticked.
with a msgbox

Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
For i = 1 To ListView1.ListItems.Count
    If ListView1.ListItems(i).Checked Then
        ListView1.ListItems(i).Selected = True
    Else
        ListView1.ListItems(i).Selected = False
    End If
Next i
End Sub
0
Comment
Question by:Jimmyx1000
  • 3
  • 2
6 Comments
 
LVL 14

Expert Comment

by:aelatik
Comment Utility
Dim X

Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
For i = 1 To ListView1.ListItems.Count
    If ListView1.ListItems(i).Checked Then
        ListView1.ListItems(i).Selected = True
 X = Item.text
    Else
        ListView1.ListItems(i).Selected = False
    End If
Next i
End Sub


X is your last item clicked
0
 
LVL 14

Expert Comment

by:aelatik
Comment Utility
Dim X

Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
For i = 1 To ListView1.ListItems.Count
    If ListView1.ListItems(i).Checked Then
        ListView1.ListItems(i).Selected = True
 X = Item.text
    Else
        ListView1.ListItems(i).Selected = False
    End If
Next i
msgbox X
End Sub
0
 
LVL 19

Expert Comment

by:Shauli
Comment Utility
'If you mean the item that was checked before the current item then:

'in form declaration area
Dim currentItem As String, lastItem As String

'in your ItemCheck event
Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
lastItem = currentItem
For i = 1 To ListView1.ListItems.Count
    If ListView1.ListItems(i).Checked Then
        ListView1.ListItems(i).Selected = True
        currentItem = Item.Text
    Else
        ListView1.ListItems(i).Selected = False
    End If
Next i

If Not lastItem = "" Then
    MsgBox lastItem
End If
End Sub

S
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:Jimmyx1000
Comment Utility
If i tick

option1 then
option2 then
option3
etc etc

and then if i untick
option1 then
option2 then
option3
etc etc

it does not seem to hold the value for the last item

Dim X

For i = 1 To ListView1.ListItems.Count
    If ListView1.ListItems(i).Checked Then
        ListView1.ListItems(i).Selected = True
 
 X = Item.Key
 
    Else
        ListView1.ListItems(i).Selected = False
    End If
Next i


MsgBox X


0
 
LVL 14

Accepted Solution

by:
aelatik earned 500 total points
Comment Utility
Oops sorry, make it :

Dim X

Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
 X = Item.text
For i = 1 To ListView1.ListItems.Count
    If ListView1.ListItems(i).Checked Then
        ListView1.ListItems(i).Selected = True
    Else
        ListView1.ListItems(i).Selected = False
    End If
Next i
msgbox X
End Sub
0
 

Author Comment

by:Jimmyx1000
Comment Utility
Well Done

thanks alot

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now