Thanks to member 'Daestrum' I have written some code which simply looks at each row in a tableview then looks at cell(1) (a date field) to see if it falls between date A and B. If so then that row number is stored in a list. After identification of rows meeting the criteria (between date A and B), I then use a javaobject to actually highlight those rows. However, my problem is the last row is always highlighted whether the criteria is met or not. And cannot see why. Row 0 is always excluded hence the loop runs from row 1. I can fudge this problem by using tbl.selectrow = 0 everytime the loop cycles. But it is not ideal as there may be occasions when I can't use the fudge. Can any one shed some light on this. Daestrum kindly showed me some js nashorn but i'd rather stick to the javaobject and crack this error.
Interestingly the last row highlighted IS NOT selected however when I test the rows selected using this code which will be confusing to a user
The last row is not displayed in the Log
HELP!
B4X:
Try
Dim jo1 As JavaObject = dtprangeFrom
Dim jo2 As JavaObject = dtpRangeTo
Dim sDate1 As String = jo1.RunMethod("getValue", Null)
Dim dDate1 As Long = DateTime.DateParse(sDate1)
Dim sDate2 As String = jo2.RunMethod("getValue", Null)
Dim dDate2 As Long = DateTime.DateParse(sDate2)
Catch
msg.Show("Select date range","Date range error")
Log(LastException)
Return
End Try
Log("Period from " & DateTime.Date(dDate1) & " to " & DateTime.Date(dDate2))
'select row
Dim jo As JavaObject = tblCB
Dim sm As JavaObject
sm = jo.RunMethod("getSelectionModel",Null)
Dim sm1 As JavaObject
sm1.InitializeStatic("javafx.scene.control.SelectionMode")
sm.RunMethod("setSelectionMode",Array(sm1.GetField("MULTIPLE")))
Dim Li As List
Li.Initialize()
For i = 1 To tblCB.Items.Size-1
tblCB.SelectedRow = i
Dim row() As Object = tblCB.SelectedRowValues
Dim DT As Long = DateTime.DateParse(row(1))
Log("Transaction selected is " & row(0) & " " & row(1) & " and long value is " & DT)
If DT >= dDate1 And DT <=dDate2 Then
'Now select the actual row
Li.Add(i)
Log(i & " is in date range" & DateTime.Date(DT))
End If
tblCB.SelectedRow = 0
Next
For Each j In Li
Log("selecting item row " & j)
jo.RunMethodJO("getSelectionModel",Null).RunMethod("select",Array(j))
Next
Interestingly the last row highlighted IS NOT selected however when I test the rows selected using this code which will be confusing to a user
B4X:
'Get selected rows from the table as list
Dim l As List
l.Initialize
l.AddAll(sm.RunMethodJO("getSelectedItems",Null))
'Display the data in the rows
Dim ss As String = ""
For Each o() As Object In l
For Each o1 In o
If ss = "" Then
ss=01
Else
ss = ss & "-" & o1
End If
Next
Log(ss)
ss = ""
Next
The last row is not displayed in the Log
HELP!