?
Solved

Listview what was last item ticked

Posted on 2004-08-03
6
Medium Priority
?
360 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
Technology Partners: 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

764 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