Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Stimulate click on selected item on ListView

Posted on 2002-04-07
5
Medium Priority
?
550 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
[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
5 Comments
 
LVL 53

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 204 total points
ID: 6925422
' I forgot to set focus
    Me.ListView.SetFocus
    Me.ListView.StartLabelEdit
0
 
LVL 53

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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.
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…
Suggested Courses

636 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