How do I remotely DoubleClick an Item in a ListBox

Posted on 2009-02-12
Last Modified: 2013-12-20
I am trying to send select an Item in a remote listbox using

Call SendMessageByString(x, LB_SELECTSTRING, 0&, "Item")

and then send

Call SendMessage(x, WM_LBUTTONDBLCLK, 0&, 0&)

so that the listbox item is clicked. However this does not work.

I have tried to use

Call SendMessageByObject(x, WM_LBUTTONUP, 0&, 0)
Call SendMessageByObject(x, WM_LBUTTONDOWN, 0&, 0)
Call SendMessage(x, WM_LBUTTONDBLCLK, 0&, 0&)

But this just selects the first item in the list box, how can I use this sequence to select the item I want?

Question by:Veeden
    LVL 15

    Expert Comment

    I'm guessing that the last 0 in the sequence is an index number.  In which case it will go to index 0 (which is generally the first in the list).  Try changing that value to the item you want and it should work.
    LVL 22

    Expert Comment

    Try this:

    Call SendMessageByString(x, LB_SELECTSTRING, -1&, ByVal "Item")
    Change "Item" to the caption of Item you want to select.


    Author Comment

    I changed it to the code below. The same effect happens, the listbox opens the row "item" gets selected however, when WM_LBUTTONDBLCLK is issued the selected item does not get clicked.
         Call SendMessageByString(x, LB_SELECTSTRING, -1&, DesktopTitle)
         Call SendMessage(x, WM_LBUTTONDBLCLK, 0&, 0&)

    Open in new window


    Author Comment

    Also EddieShipman mentioned (

    how to do this, but I cant get the mouse coordinates to work properly
    LVL 22

    Accepted Solution

    To get Mouse coordinates relative to a control use this code where m_hWnd is the handle of control:

    Private Type POINTAPI    
       x    As Long
       y    As Long
    End Type

    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long

    Dim pt As POINTAPI
    GetCursorPos pt
    ScreenToClient m_hWnd, pt

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    Introduction While answering a recent question ( 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…
    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…

    754 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

    17 Experts available now in Live!

    Get 1:1 Help Now