Double+and+single+click+in+a+listbox

=Double and single click in a listbox=

By default, listbox provide double-click handler. Helpfile says a way to re-use that event handler for single click:

> **print #handle.ext, "singleclickselect"** > This tells Just BASIC to jump to the control's branch label on a single click, instead of the default double click.

It does not say, but if fact, you can use it in a form > **print #handle.ext, "singleclickselect [SingleClickEventHandler]"** and get separate handlers for double-click and single click.

One scenario might be single click updates shown info based on selection, while double click opens item for editing.

There is small thing - if you do some testing you'll see that if you do double click, you first get single-click event, second double-click event. In the scenario above this doesn't actually matter. But if you for some reason wish to get rid of (extra) single-click event, you can use trick with timer shown in [|Double and single click in graphicbox]:

code format="lb" 'Problem: if you have both double click and single click handlers, on double click, both events fire 'Using timer, you can filter-off unwanted single clicks '(Though, if you have single click updating something on selection, and double click working on that update, ' then both events aone after another works just fine.) nomainwin

WindowWidth = 550 WindowHeight = 410

UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)

texteditor #main.texteditor1, 222, 16, 232, 280 listbox #main.listbox2, array$(, [listbox2DoubleClick], 30, 11, 160, 280

open "Single and double click listbox test" for window_nf as #main print #main, "trapclose [quit.main]" #main.listbox2 "singleclickselect [listbox2SingleClick]"

for i = 1 to 5 array$(i)= "Item ";i next #main.listbox2 "reload"

wait

[quit.main] Close #main END

[listbox2DoubleClick] timer 0 #main.listbox2 "selection? selected$" #main.texteditor1 "DblClick "; selected$ wait

[listbox2SingleClick] timer 200, [clickTimer] wait

[clickTimer] timer 0 #main.listbox2 "selection? selected$" #main.texteditor1 "SnglClick "; selected$ wait

code