Listbox and enter key

tsteward

Well-Known Member
Licensed User
I want to have a listbox where I can scroll up and down using the cursor keys (no problem here it does that by default) now I wish to trigger a sub when I press enter or cMiddle.

Is this possible?
How please?

Thank you,

Tony
 

Erel

Administrator
Staff member
Licensed User
It is possible with the Door library:
Obj is an Object and keyDownEvent is an Event (from the Door library).
B4X:
Sub Globals
    'Declare the global variables here.

End Sub

Sub App_Start
    Form1.Show
    obj.New1(False)
    obj.FromControl("Listbox1")
    keyDownEvent.New1(obj.Value,"KeyPress")
End Sub

Sub keyDownEvent_NewEvent
    obj.Value = keyDownEvent.Data
    If Asc(obj.GetProperty("KeyChar")) = 13 Then
        Msgbox("The following item was selected: " & _ 
            ListBox1.Item(ListBox1.SelectedIndex))
    End If
End Sub
 

tsteward

Well-Known Member
Licensed User
Thanks Erel,
I knew door lib could do it I just didn't know enough to know how.

Ta mate :)
 
Top