Solved

Listview what was last item ticked

Posted on 2004-08-03
6
351 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
ID: 11708873
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
ID: 11708900
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
ID: 11708925
'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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:Jimmyx1000
ID: 11709005
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
ID: 11709089
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
ID: 11709149
Well Done

thanks alot

0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

778 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