StPendl StPendl Sep 10, 2007 - "changed heading"

==How to have a single- and a double-click handler for a listbox== 
[[user:StPendl|1189413695]]

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 [[http://babek.info/libertybasicfiles/lbnews/nl126/doubleclick.htm|Double Click Demo in Newsletter 126]]

[[code format="vbnet"]]
    nomainwin

    for i = 1 to 10
        array$(i) = str$(i)
    next

    listbox #m.lb, array$(, [DoubleClickAction], 10, 10, 200, 200
    statictext #m.txt, "Select an item or double click it.", 10, 220, 200, 20

    open "test listbox event handlers" for window as #m
    #m "trapclose [quit]"
    #m.lb "singleClickSelect [SingleClickAction]"
    wait

[SingleClickAction]
    calldll #user32, "GetDoubleClickTime", delay as ulong
    timer delay, [continue]
    wait

[continue]
    timer 0
    #m.txt "Single Click Action"
    wait

[DoubleClickAction]
    timer 0
    #m.txt "Double Click Action"
    wait

[quit]
    close #m
    end
[[code]]