B4J Question [Solved] Swap list (TableViewExtended) Problem

magi6162

Well-Known Member
Licensed User
B4X:
dim tvG as Table TableView
dim tveGita as TableViewExtended
tveGita.InitializeByExtending(tvG)

this Ok, swap rows:
B4X:
Sub btnDown_Action
   Private s,d As Object
   If tveGita.SelectedRows.Length = 1 Then
     If tveGita.SelectedRows(0) < (tveGita.Items.Size - 1) Then
       s = tveGita.Items.Get(tveGita.SelectedRows(0))
       d = tveGita.Items.Get(tveGita.SelectedRows(0)+1)
       tveGita.Items.Set(tveGita.SelectedRows(0)+1,s)
       tveGita.Items.Set(tveGita.SelectedRows(0),d)
       tveGita.SelectedRow = tveGita.SelectedRows(0)
     End If
   End If
End Sub

this don't swap rows:
B4X:
Sub btnUp_Action
    Private s,d As Object
    If tveGita.SelectedRows.Length = 1 Then
        If tveGita.SelectedRow > 0 Then
            s = tveGita.Items.Get(tveGita.SelectedRow)
            d = tveGita.Items.Get(tveGita.SelectedRow-1)
            tveGita.Items.Set(tveGita.SelectedRow-1,s)
            tveGita.Items.Set(tveGita.SelectedRow,d)

            tveGita.SelectedRow = tveGita.SelectedRow-1
        End If
    End If
End Sub

please help me
 

magi6162

Well-Known Member
Licensed User
I try too:
B4X:
Sub btnUp_Action
    Private s,d As Object
    If tveGita.SelectedRows.Length = 1 Then
        If tveGita.SelectedRows(0) > 0 Then
            s = tveGita.Items.Get(tveGita.SelectedRow)s(0)
            d = tveGita.Items.Get(tveGita.SelectedRows(0)-1)
            tveGita.Items.Set(tveGita.SelectedRows(0)-1,s)
            tveGita.Items.Set(tveGita.SelectedRows(0),d)

            tveGita.SelectedRow = tveGita.SelectedRows(0)-1
        End If
    End If
End Sub
but don't swap the rows
PS: I have two button. One Move current row down (btnDown)
Another button moves the current line up (btnUp) <<-----------this don't swap the rows:(:(

Thank for help
 
Upvote 0

stevel05

Expert
Licensed User
Can you provide an example project (File / Export as zip) so that it can be tested and debugged, and we can see exactly what you've done. Otherwise we have to write one which takes time. It will help us to help you.
 
Upvote 0

magi6162

Well-Known Member
Licensed User
so it works:
B4X:
Sub btnUp_Action
    Private s,d As Object
    Private k As Int
    If tveR.SelectedRows.Length = 1 Then
        If tveR.SelectedRows(0) > 0 Then
            s = tveR.Items.Get(tveR.SelectedRows(0))
            d = tveR.Items.Get(tveR.SelectedRows(0)-1)
            k = tveR.SelectedRows(0)
            tveR.Items.Set(k-1,s)
            tveR.Items.Set(k,d)
            tveR.SelectedRow = k-1
        End If
    End If
End Sub
 
Upvote 0

stevel05

Expert
Licensed User
It looks like the selected row may change when you set a data item. This works:
B4X:
Sub btnUp_Action
    Private s(),d() As Object
    Log(tveR.SelectedRows(0))
    If tveR.SelectedRows.Length = 1 Then
        If tveR.SelectedRows(0) > 0 Then
            Dim Row As Int = tveR.SelectedRows(0)
            s = tveR.Items.Get(Row)
            d = tveR.Items.Get(Row-1)
            tveR.Items.Set(Row-1,s)
            tveR.Items.Set(Row,d)
            tveR.SelectedRow = Row-1
        End If
    End If
End Sub

Ok, you've already found it.
 
Upvote 0
Top