B4J Question How to disable TableView SelectedRowChanged?

gezueb

Active Member
Licensed User
Longtime User
I have a program that displays a tableview. When I click on a row, a SelectedRowChanged event is triggered. This sub calls another form with some detail info about the item clicked. The tableview is closed. So far so good.
When I leave the detail form I want to return to the form with the original tableview. As soon as it is started, it triggers the SelectedRowChanged event again, but with row index - 1 which blows up the code or loops forever if catched on this condition. How can I reset this event so that it triggers only when a row is clicked again? I have tried TableView.clearselection, to no avail. Many thanks for advice.
 

micro

Well-Known Member
Licensed User
Longtime User
I have a program that displays a tableview. When I click on a row, a SelectedRowChanged event is triggered. This sub calls another form with some detail info about the item clicked. The tableview is closed. So far so good.
When I leave the detail form I want to return to the form with the original tableview. As soon as it is started, it triggers the SelectedRowChanged event again, but with row index - 1 which blows up the code or loops forever if catched on this condition. How can I reset this event so that it triggers only when a row is clicked again? I have tried TableView.clearselection, to no avail. Many thanks for advice.
Hi
Can you use a JavaObject
B4X:
Dim jo As JavaObject = TableView
jo.RunMethodJO("getSelectionModel",Null).RunMethod("clearSelection",Null)
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
Thank you, Micro, I tried this already. Seems to do the same as TableView.clearselection. It triggers the event again, but with row index -1!
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
What is the code in your SelectedRowChanged Event?

I have and example:
B4X:
Sub tvCityLocations_SelectedRowChanged(Index As Int, Row() As Object)
    Log("selected row changed to " & Index)
    If (Index > -1 And Index < tvCityLocations.Items.Size) Then
        Private mp As Map = Row(4)
        Private name As String = mp.Get("slug")
        Private Marker As Marker= msCityCenter.GetMarkerFromName(name)
        If (Marker <> Null) Then
            msCityCenter.ShowMarkerInfo(Marker)
        End If
    End If
End Sub

and it works as you would expect. The table contains a hidden row, row(4) with data in it.
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
Micro:
If Index = -1 then Return

That was the first thing I tried. I have not yet found out where the return leads to. But maybe I did it the wrong way.

Digitwell: I do something similar. It works well if I leave the Tableview in the background. Then, on return, the same selected row is highlighted again and all is well. I wanted to re-do the tableview from scratch to make sure my database access is properly initialized, but that does not work as it triggers the ...changed event (again).
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
I would say that this is normal behavior as when you clear the tableview to recreate it, you are implicitly deselecting the previously selected item.

I have not yet found out where the return leads to. But maybe I did it the wrong way.

Why do you need to know?
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
That's what I assume too (that the previously selected item is gone after restart). However, what seems to be still lurking is the associated changerow event. Anyway, thank you for your help. I keep that tableview live and return to it which works perfectly okay (row still selected until klicked otherwise).
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
I have a program that displays a tableview. When I click on a row, a SelectedRowChanged event is triggered. This sub calls another form with some detail info about the item clicked. The tableview is closed. So far so good.
Well, you leave a selection process and go back to that situation without flagging the processing of the triggered action. What about to add a routine to show the updated result again without a selection before you call the other form?
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Could you not just hide the TableView (visible=false) then when you have shown the details simply show the TableView again (visible=true) this will keep the selection and not trigger the SelectedRowChanged event.
 
Last edited:
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
Thanks all of you, problem is solved with your help! I will keep the tableview in th ebackground (hidden or not)!
 
Upvote 0
Top