B4J Question TableView - simulate STRG - multiselect without ctrl

Patent

Member
Licensed User
Longtime User
Dear Community,

is it possible to "simulate" the STRG Key press while selecting Rows in a tableview,
so to select different and many rows by mouseclick (without pressing STRG)?

thanks
 

Patent

Member
Licensed User
Longtime User
by pressing STRG on the Keyboard. and this works fine in b4j.
i want to do this without keyboard,for instance by setting a toggle button.

big sorry: have forgotten that most of you are using a internat. keyboard. its the CTRL button on yours........
 
Upvote 0

Patent

Member
Licensed User
Longtime User
this works with full "windows like" behavior (CTRL a(ll), Shift, CTRL)....
 

Attachments

  • tableView.zip
    2 KB · Views: 386
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Would have saved 5 posts if you wrote that you are changing the selection mode with JavaObject.

You can use this code to handle the pressed event before it reaches the default handler and manage the selection yourself:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private TableView1 As TableView
   Private selectedRows As List
   Private tvSelModel As JavaObject
   
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   MainForm.Show
   MainForm.Title = "Table Example with CTRL Function"
   
   TableView1.SetColumns(Array As String("Col1", "Col2"))
   For i = 1 To 100
     TableView1.Items.Add(Array(i, i))
   Next
   selectedRows.Initialize
   Dim jotable As JavaObject=TableView1

   'Get the Selection Mode Enum:
   Dim joSelMode As JavaObject
   joSelMode.InitializeStatic("javafx.scene.control.SelectionMode")
   
   'get Selection Model:
   tvSelModel = jotable.RunMethodJO("getSelectionModel", Null)
   
   'set the selectionmode of the tableview by using the enum
   tvSelModel.RunMethod("setSelectionMode",Array(joSelMode.GetField("MULTIPLE")))
   Dim r As Reflector
   r.Target = TableView1
   r.AddEventFilter("TableView1", "javafx.scene.input.MouseEvent.MOUSE_PRESSED")
End Sub

Sub TableView1_Filter (EventData As Event)
   Dim jo As JavaObject = EventData
   Dim targetType As String = GetType(jo.RunMethod("getTarget", Null))
   If targetType = "javafx.scene.control.TableColumn$1$1" Then
     Dim row As JavaObject = jo.RunMethodJO("getTarget", Null).RunMethod("getTableRow", Null)
     Dim index As Int = row.RunMethod("getIndex", Null)
     Dim i As Int = selectedRows.IndexOf(index)
     If i > -1 Then
       selectedRows.RemoveAt(i)
       tvSelModel.RunMethod("clearSelection", Array(index))
       
     Else
       selectedRows.Add(index)
       Dim indices(selectedRows.Size - 1) As Int
       For i = 0 To indices.Length - 1
         indices(i) = selectedRows.Get(i + 1)
       Next
       tvSelModel.RunMethod("selectIndices", Array(selectedRows.Get(0), indices))
     End If
     EventData.Consume
   Else if targetType = "javafx.scene.control.TableRow" Then
     EventData.Consume
   End If
End Sub
 
Upvote 0

Similar Threads

Top