Solved

Listview what was last item ticked

Posted on 2004-08-03
6
357 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

729 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