Solved

Stimulate click on selected item on ListView

Posted on 2002-04-07
5
543 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 50

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 50

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…
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…

777 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