How to have a single- and a double-click handler for a listbox

- StPendl StPendl Sep 10, 2007

Most people do not know, that a listbox can respond to a single-click by setting the singleClickSelect property.
You can have a different event handler for single-clicks by adding a branch label (singleClickSelect [action]) too.

The problem we have, when using both event handlers, is to know which one to use, because Windows sends the single-click and double-click messages to the control, when double-clicking a listbox item.

Here is a demo for using both event handlers based on the Double Click Demo in Newsletter 126

    for i = 1 to 10
        array$(i) = str$(i)
    listbox, array$(, [DoubleClickAction], 10, 10, 200, 200
    statictext #m.txt, "Select an item or double click it.", 10, 220, 200, 40
    open "test listbox event handlers" for window as #m
    #m "trapclose [quit]" "singleClickSelect [SingleClickAction]"
    calldll #user32, "GetDoubleClickTime", delay as ulong
    timer delay, [continue]
    timer 0
    #m.txt "Single Click Action"; chr$(13); "Double-Click-Delay: "; delay; "ms"
    ' reset selection "selectindex 0"
    timer 0
    #m.txt "Double Click Action"
    ' reset selection "selectindex 0"
    close #m