Listbox Events

I have a listbox that I want users to edit and delete items, I have setup cellclick to allow editing of items in the box and doubleclick to delete selected item but only cellclick is working when I double click the listbox thinks the cell is to be edited how can I have both events working

Search the forum is your friend :

I get same results with this code dobleclick event does not work only activates the cellclick to edit the cell in listbox. I’m looking to delete current item on doubleclick or edit with single click

That seems like really bad user interface desig to me …. but maybe that’s just me …

lol, nope, Markus I agree completely.

Yes, this is unusual UI. In a similar situation I added a thin column on the right with icons and only double clicking on the icon deletes.

But if you really want to do this the issue is that CellClick happens first and shows the EditableCell, then a second click goes to that editing cell, not the Listbox, so no double click is detected. Instead you’ll have to detect the double click yourself in the editing cells MouseDown.

[code]Property lastClickTime As double

Function CellClick(row as Integer, column as Integer, x as Integer, y as Integer) As Boolean

//store the time of this first click
lastClickTime = Microseconds

//show the editcell
me.EditCell(row, column)

//hook up a MouseDown handler to the editing cell
AddHandler TextField(me.ActiveCell).MouseDown, AddressOf handle_ActiveMDown

//return that you handled it but really this doesn’t make a difference
return false

End Function

Function handle_ActiveMDown(sender As TextField, x As integer, y As integer) As boolean

//collect the systems double click time in microseconds
dim doubleClickMicroSec As double
#If TargetCocoa then
declare function NSClassFromString lib “Foundation” (clsName As CFStringRef) As Ptr
declare function dTime lib “AppKit” selector “doubleClickInterval” (cls As Ptr) As double
doubleClickMicroSec = dTime(NSClassFromString(“NSEvent”)) * 1000000
#Elseif TargetWin32 then
Declare Function GetDoubleClickTime Lib “User32.DLL” As Integer
doubleClickMicroSec = GetDoubleClickTime * 1000

if Microseconds - lastClickTime < doubleClickMicroSec then
//perform double click Action here

End Function[/code]

Note, this assumes your editingcell type is a TextField, not a TextArea.

To delete a Row, I use cmd-Del, OS X (ctrl-Del on Windows).

I started with Delete only, but even if I do not made mistakes, I added cmd / ctrl later to avoid a wrong delete (that is so easy).

cmd-v / ctrl-v add a new Row. Sometimes I add a new row “by error”.

Why not have a separate column with a “delete” icon in it? Or just use the DELETE key and make asking for confirmation an option in your preferences.

This is an idea, but I had troubles with an icon in a ListBox(when a Row is selected, the Row look was bad), so I stop thinking about icons in a ListBox (probably).

On the other way, why don’t put a ToolBar with commonly used features (like delete the selection) ?

At last, I am a man of keyboard (what I had long before I saw my first computer Mouse)… ;-:slight_smile:

I tend to use the Contextual menus for deleting a row in a listbox. I like the idea that the user has to act intentionally for something that can be data destructive. Something like a DoubleClick can sometimes be done accidentally when a single click was intended.

I agree with Emile, if you rely on the keyboard then use a key combination to help avoid accidental deletions.

The other way to get double click is to overlay a canvas and use its doubleClick event.

Personally, I would never use doubleClick to delete. It is absolutely non standard and very dangerous. I would rather use a contextual menu. But that’s me.

How many (Selected) Rows can you delete with a ContextualMenu ?

I think this is the reason why I used cmd-Delete (OS X) ctrl-Delete (Windows).

[quote=251514:@Emile Schwarz]How many (Selected) Rows can you delete with a ContextualMenu ?

I think this is the reason why I used cmd-Delete (OS X) ctrl-Delete (Windows).[/quote]

Maybe Karen’s post might help:

Thank you Peter.

Hello David!
I do the following to recognize a double-click:

  1. I have put the method DoppelKlickIntervall into a own class
  2. I use the method into a MouseDown event

Here is the code

[code]Public Function DoppelKlickIntervall() as integer
#if TargetMacOS
'Declare Function GetDblTime Lib “Carbon” () as Integer

Const CocoaLib As String = "Cocoa.framework"
declare function NSClassFromString lib CocoaLib(aClassName as CFStringRef) as ptr
declare function doubleClickInterval lib CocoaLib selector "doubleClickInterval" (aClass as ptr) as double
  'doubleClickTime = GetDblTime()
  RefToClass = NSClassFromString("NSEvent")
  return doubleClickInterval(RefToClass) * 60
catch err as ObjCException
  MsgBox err.message


#if TargetWin32
Declare Function GetDoubleClickTime Lib “User32.DLL” () as Integer
return GetDoubleClickTime()
catch err as ObjCException
msgbox err.message

return 0
End Function[/code]

And into the MouseDown event:

[code]dim Bypass as new EcClass
dim currentClickTicks as Integer
static lastClickTicks as integer
static lastClickX as Integer
static lastClickY as Integer

currentClickTicks = ticks

if not IsContextualClick then 'kein Rechtsklick
if (currentClickTicks - lastClickTicks) <= Bypass.DoppelKlickIntervall then 'Zeit ist im Doppelklickzeitraum
if abs(X - lastClickX) <= 5 and abs(Y - LastClickY) <= 5 then 'beide Clicks liegen nah aneinander

    lastClickTicks = currentClickTicks
    lastClickX = X
    lastClickY = Y
    dim calendar as new CalendarWindow
    me.text = calendar.GetDate("Belegdatum",me.text,,self.left+me.Left)
    'me.SelStart  = 0
    'me.SelLength = 0
  end if
end if

lastClickTicks = currentClickTicks
lastClickX = X
lastClickY = Y

end if[/code]