I'm working on tableview where when i click a row data of row are loaded in differents fields and when i want delete it I click DeleteButton that delete the selected row (very easy).
I implemented multiple selection of rows in TableView to delete more rows in one time only.
All selected rows are taken from GetSelectedItems function.
TableViewUtils
The problem rise when i delete all rows except one. The remained row is selected (grey selection like if focus changed) but don't rise TableView1_SelectedRowChanged(Index As Int, Row() As Object) so fields don't fill. All other deleted rows rise the event instead, that create more work for program.
Deleted rows function
Assign fields value when change row
So i would to understand how to lock TableView1_SelectedRowChanged events rised from deleted rows.
I implemented multiple selection of rows in TableView to delete more rows in one time only.
All selected rows are taken from GetSelectedItems function.
TableViewUtils
B4X:
Sub MultipleSelection(tv As TableView)
Dim re As Reflector
re.Target = tv
re.Target = re.RunMethod("getSelectionModel")
re.Target = re.RunMethod2("setSelectionMode","MULTIPLE","javafx.scene.control.SelectionMode")
End Sub
Sub GetSelectedItems(tv As TableView) As List
Dim re As Reflector
re.Target = tv
re.Target = re.RunMethod("getSelectionModel")
re.Target = re.RunMethod("getSelectedItems")
Dim l As List
l.Initialize
l.AddAll(re.Target)
Return l
End Sub
The problem rise when i delete all rows except one. The remained row is selected (grey selection like if focus changed) but don't rise TableView1_SelectedRowChanged(Index As Int, Row() As Object) so fields don't fill. All other deleted rows rise the event instead, that create more work for program.
Deleted rows function
B4X:
Private Sub deleteRecord_Click
If TableView1.SelectedRow = -1 Then Return
Dim rows As List = TableViewUtils.GetSelectedItems(TableView1)
For i = 0 To rows.Size-1
Dim row() As String = rows.Get(i)
Dim code As String = row(0)
Dim kCode As KdrCode = KConverter.ParseCode(code)
ManageKCSV.KCSVClass.DeleteRecord(kCode)
Dim index As Int = TableView1.Items.IndexOf(row)
TableView1.Items.RemoveAt(index)
Next
MainKCSV.saved = False
End Sub
Assign fields value when change row
B4X:
Private Sub TableView1_SelectedRowChanged(Index As Int, Row() As Object)
If TableView1.SelectedRow = -1 Or Index = -1 Then Return 'index = -1 se la selezione è multipla
Dim code As String = Row(0)
Dim kCode As KdrCode = KdrillsConverter.ParseCode(code)
Dim kDescription As KdrDescription = ManageKCSV.KCSVClass.GetKdrDescription(kCode)
'Set Layout
diametroRec.Text = kDescription.Diametro
lunghezzaRec.Text = kDescription.Lunghezza
prezzoRec.Text = kDescription.Prezzo
legantiRec.Items.Clear
If kDescription.Legante.IsInitialized Then
legantiRec.Items.AddAll(kDescription.Legante)
End If
ChangeSavedCheckStatus(True)
End Sub
So i would to understand how to lock TableView1_SelectedRowChanged events rised from deleted rows.