Solved

Stimulate click on selected item on ListView

Posted on 2002-04-07
5
547 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 52

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 52

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

Independent Software Vendors: 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!

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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.
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…
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…

689 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