Solved

Listview what was last item ticked

Posted on 2004-08-03
6
350 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

910 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

21 Experts available now in Live!

Get 1:1 Help Now