Solved

Stimulate click on selected item on ListView

Posted on 2002-04-07
5
540 Views
Last Modified: 2012-08-14
Hi,

How to stimulate click on selected item on a Listview control, which its LabelEdit Property set to Automatic.

The purpose is i would like to click a button, let say to rename the item (The situation when click on a selected item on listview and labeledit is automatic).

Maybe just like Situation where when right click > select Rename from a file in a Folder.

I'm now try to use the mouse_event API to do it but still can't figure it out currently.

Any methods are welcome, thanks
0
Comment
Question by:Ryan Chong
  • 3
  • 2
5 Comments
 
LVL 49

Author Comment

by:Ryan Chong
Comment Utility
Well, currently this is what i done:

Declaration:

Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
Private Const MOUSEEVENTF_MIDDLEDOWN = &H20
Private Const MOUSEEVENTF_MIDDLEUP = &H40
Private Const MOUSEEVENTF_MOVE = &H1
Private Const MOUSEEVENTF_ABSOLUTE = &H8000
Private Const MOUSEEVENTF_RIGHTDOWN = &H8
Private Const MOUSEEVENTF_RIGHTUP = &H10

Private Type POINTAPI
    x As Long
    y As Long
End Type
Dim iPoint As POINTAPI

Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
________________________________

Rename Button:

Private Sub cmdRename_Click()
    If Not ListView.SelectedItem Is Nothing Then
        i = SetCursorPos(iPoint.x, iPoint.y)
        ListView.SetFocus
        mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, iPoint.x, iPoint.y, 0&, 0& 'cButt, dwEI
    End If
End Sub
________________________________

Code to loading the data into ListView:

OpenConnection "Select Mass_id, Mass_name, Tablename, FilteredBy from " & TableMassCom, GlobalADO
    ListView.Sorted = False
    For i = 1 To GlobalADO.RecordCount
        ListView.ListItems.Add i, , "" & GlobalADO.Fields!Mass_name 'Mass_name
        ListView.ListItems(i).Tag = "" & GlobalADO.Fields!Mass_id 'Mass_id
        ListView.ListItems(i).SubItems(1) = "" & GlobalADO.Fields!FilteredBy 'FilteredBy
        ListView.ListItems(i).ListSubItems(1).Tag = "" & GlobalADO.Fields!TableName 'Tablename
        GlobalADO.MoveNext
    Next i
    ListView.Sorted = True
    If ListView.ListItems.Count > 0 Then ListView.ListItems(1).Selected = True: iPoint.x = ListView.ListItems(1).Left + 20: iPoint.y = ListView.ListItems(1).Top + (ListView.ListItems(1).Height) / 2

Almost perfect.. but is there an alternative?

0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
    ListView.StartLabelEdit
0
 
LVL 15

Accepted Solution

by:
ameba earned 51 total points
Comment Utility
' I forgot to set focus
    Me.ListView.SetFocus
    Me.ListView.StartLabelEdit
0
 
LVL 49

Author Comment

by:Ryan Chong
Comment Utility
Simply and perfect! How can i forget this?! (bcos i previously know this method :P) Anyway thanks ya, ameba! :)

Cheers
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
Thanks  :-)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

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