Solved

Stimulate click on selected item on ListView

Posted on 2002-04-07
5
542 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
ID: 6924698
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
ID: 6925413
    ListView.StartLabelEdit
0
 
LVL 15

Accepted Solution

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

Author Comment

by:Ryan Chong
ID: 6926998
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
ID: 6927019
Thanks  :-)
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

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…
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.
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 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…

919 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

22 Experts available now in Live!

Get 1:1 Help Now