### Key Filter ListView

Example of a key filter for a ListView (requires the jReflection library).
Keys filtered with actions:
ENTER: Close the dialog returning the item selected id
ESCAPE: Close the dialog without returning an item (-1)
`Private Sub Class_Globals
Private ListView_Items As ListView
Public ItemSelected As Int
...
End Sub`
Define the Event Filter
Dim r As Reflector
r.Target = ListView_Items
r.AddEventFilter("ListView_Items_Key", "javafx.scene.input.KeyEvent.KEY_PRESSED")
Define the Keyfilter for the ListView.
`Private Sub ListView_Items_Key_Filter (EventData As Event)
Dim jo As JavaObject = EventData
Dim code As String = jo.RunMethod("getCode", Null)
If code = "ENTER" Then
Dialog_Select_Action
EventData.Consume
End If
If code = "ESCAPE" Then
Dialog_Cancel_Action
EventData.Consume
End If
End Sub`
Region Actions
' Close the dialog with the item selected.
' Return >= 0
`Private Sub Dialog_Select_Action
Form_SelectItem.Close
End Sub`
' Close the dialog without the item selected.
' Returns -1.
`Private Sub Dialog_Cancel_Action
ItemSelected = -1
Form_SelectItem.Close
End Sub`
End Region

Changed: 2018-04-22 09:19, Category: KeyEvents, File: T6C211M2166.htm, ID: 2166