B4A Class FlexibleTable, JumpToRowAndSelect problem

In the flexibletable class (Table) I added a routine to incrementally add to the table with a list of 1D string arrays.
This was needed to deal with very large text files.
All working fine.
I came across a problem though with the routine JumpToRowAndSelect, in that it didn't go to the specified row.
Running the same line again:

B4X:
oTable.JumpToRowAndSelect(0, iRow - 1)

Did did the job, but I thought this wasn't quite the right solution, so I looked for other ways to fix this.
I came up with this solution, which works fine and seems to be fine as well when used in other situations, so when not
incrementally adding to a table:

B4X:
Private Sub SVF_ScrollChanged(Position As Int)
    
    'Log("SVF_ScrollChanged, Position: " & Position)
    'Log("SVF_ScrollChanged, SV2.VerticalScrollPosition: " & SV2.VerticalScrollPosition)
    'Log("Sub SVF_ScrollChanged, cMP.PageCode: " & cMP.PageCode & ", " & Enums.arrB4XPagesNames(cMP.PageCode))
    
    '------------------------------------------------------------------------------------------------
    'this was added to solve a problem where Go2Row didn't go to the last row when run via page P_TXT
    'seems it can be used always, so maybe we don't need the If clause
    '------------------------------------------------------------------------------------------------
    If cMP.PageCode = Enums.eB4XPages.iTextData Then
        Position = SV2.VerticalScrollPosition
    End If
    
    SVFScrolls = True
    
    If Position <> 0 Then 'added this to avoid the problem with scroll back to row zero with an initial down scroll
        If SV2Scrolls = False Then
            Scroll(SV2PosX, Position)
            SV2.VerticalScrollPosition = Position
        End If
    End If
    
    SVFScrolls = False
    
End Sub

Maybe Klaus could comment if this solution would always work or if it could fail.
The whole scrolling related code is a bit complex, so I couldn't work this out.

RBS
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
I had the problem in other applications too.
And the workaround was repeating the scroll to call, in some cases even more the two times.
But these variables do not exist in the Table class.
Good to hear I wasn't the only one coming across this problem and also you solved it (at least initially) the same way.
What variables are you referring to?

The only relevant code line I posted was this one:

B4X:
Position = SV2.VerticalScrollPosition

The question is if you think this would always work.
If so then Sub SVF_ScrollChanged could be changed like this:

B4X:
Private Sub SVF_ScrollChanged

    Dim iPosition As Int = SV2.VerticalScrollPosition
    
    SVFScrolls = True
    
    If Position <> 0 Then 'added this to avoid the problem with scroll back to row zero with an initial down scroll
        If SV2Scrolls = False Then
            Scroll(SV2PosX, Position)
            SV2.VerticalScrollPosition = Position
        End If
    End If
    
    SVFScrolls = False
    
End Sub

RBS
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Good to hear I wasn't the only one coming across this problem and also you solved it (at least initially) the same way.
What variables are you referring to?

The only relevant code line I posted was this one:

B4X:
Position = SV2.VerticalScrollPosition

The question is if you think this would always work.
If so then Sub SVF_ScrollChanged could be changed like this:

B4X:
Private Sub SVF_ScrollChanged

    Dim iPosition As Int = SV2.VerticalScrollPosition
   
    SVFScrolls = True
   
    If Position <> 0 Then 'added this to avoid the problem with scroll back to row zero with an initial down scroll
        If SV2Scrolls = False Then
            Scroll(SV2PosX, Position)
            SV2.VerticalScrollPosition = Position
        End If
    End If
   
    SVFScrolls = False
   
End Sub

RBS
Just to avoid any possible confusion:
In the posted Sub Position should be iPosition.

RBS
 

klaus

Expert
Licensed User
Longtime User
What variables are you referring to?
Those, in the routine in post #1:
B4X:
    If cMP.PageCode = Enums.eB4XPages.iTextData Then
        Position = SV2.VerticalScrollPosition
    End If

You are defing a new variable iPosition, but it is not used ?
Should iPosition be used in this line ?
B4X:
    If iPosition <> 0 Then 'added this to avoid the problem with scroll back to row zero with an initial down scroll
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Those, in the routine in post #1:
B4X:
    If cMP.PageCode = Enums.eB4XPages.iTextData Then
        Position = SV2.VerticalScrollPosition
    End If

You are defing a new variable iPosition, but it is not used ?
Should iPosition be used in this line ?
B4X:
    If iPosition <> 0 Then 'added this to avoid the problem with scroll back to row zero with an initial down scroll
Yes.
I did mention I mis-typed Position, should be iPosition.

RBS
 

klaus

Expert
Licensed User
Longtime User
I am still confused.
Where should iPosition be used ?
This code does not work:
B4X:
Private Sub SVF_ScrollChanged(Position As Int)
    Dim iPosition As Int = SV2.VerticalScrollPosition

    SVFScrolls = True

    If iPosition <> 0 Then
        If SV2Scrolls = False Then
            Scroll(SV2PosX, Position)
            SV2.VerticalScrollPosition = Position
        End If
    End If
    
    SVFScrolls = False
End Sub
If the right ScrollView is on top and you move the left one, the right one does not move anymore.
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
I am still confused.
Where should iPosition be used ?
This code does not work:
B4X:
Private Sub SVF_ScrollChanged(Position As Int)
    Dim iPosition As Int = SV2.VerticalScrollPosition

    SVFScrolls = True

    If iPosition <> 0 Then
        If SV2Scrolls = False Then
            Scroll(SV2PosX, Position)
            SV2.VerticalScrollPosition = Position
        End If
    End If
   
    SVFScrolls = False
End Sub
If the right ScrollView is on top and you move the left one, the right one does not move anymore.
The Sub should be like this:

B4X:
Private Sub SVF_ScrollChanged

    Dim iPosition As Int = SV2.VerticalScrollPosition
    
    SVFScrolls = True
    
    If iPosition <> 0 Then 'added this to avoid the problem with scroll back to row zero with an initial down scroll
        If SV2Scrolls = False Then
            Scroll(SV2PosX, iPosition)
            SV2.VerticalScrollPosition = iPosition
        End If
    End If
    
    SVFScrolls = False
    
End Sub

You can add Postition As Int (not iPosition) as an argument, but it won't be used then.

Can you give me an example where that code will fail?

RBS
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Your last code does not work at all when left columns are blocked.
Replacing Position by iPosition you ignore the scroll changes of the first columns.
When you scroll the first columns the right columns do not move.
OK, thanks.
I don't think I ever blocked table columns, so didn't come across that as a problem.
Will have a look into blocking columns.
I could just add an If clause, so if columns are blocked then run JumpToColumnAndSelect twice, otherwise
I could do as in the posted Sub.

RBS
 

klaus

Expert
Licensed User
Longtime User
Now i understand the problem.
When no columns are blocked, the SVF_ScrollChanged routine should never be executed.
Therefore change the routine like this:

B4X:
Private Sub SVF_ScrollChanged(Position As Int)
    If mFirstColumnFixed = True Then
        SVFScrolls = True
        If SV2Scrolls = False Then
            Scroll(SV2PosX, Position)
            SV2.VerticalScrollPosition = Position
        End If
        SVFScrolls = False
    End If
End Sub
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Now i understand the problem.
When no columns are blocked, the SVF_ScrollChanged routine should never be executed.
Therefore change the routine like this:

B4X:
Private Sub SVF_ScrollChanged(Position As Int)
    If mFirstColumnFixed = True Then
        SVFScrolls = True
        If SV2Scrolls = False Then
            Scroll(SV2PosX, Position)
            SV2.VerticalScrollPosition = Position
        End If
        SVFScrolls = False
    End If
End Sub
OK, thanks, will change that.

RBS
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
The Table class has been updated to version 3.36 in the first post.
Removed unnecessary execution of SVF_ScrollChanged when no columns are blocked
Just one thing about this.
I don't use fixed columns normally, but I tried it and fixed the first column:

B4X:
tblTextFile.NumberOfFixedColumns = 1

Now what happens if that I scroll with the finger on the first column the first column will scroll and the rest of the table is fixed.
Also after a few scrolls it will show the grey back ground (no cell data) in the first column.
Maybe this is just caused by something I had changed from the original class, but I thought it was worth mentioning this as it doesn't
look quite OK.

RBS
 
Top