ScrollView and Database Issues

jpvniekerk

Active Member
Licensed User
Longtime User
I am having problems with a part of a program...

I have programmed a ScrollView to show a list of items from a database. This works fine (just as I want it to).

The Scrollview is accessed from the "main" sreen. I have simulated the use in the attached program.

I have two problems:

1) When I open the list, everything works fine. I click on an item, the row gets colored and the "TickID" is shown in the Title Bar. Now when I close the list (Press "Menu" then "Close List"), and open the list again (press the button on the main screen), the list comes up fine, but when I click on the list, it does not show the color like it did the first time. The value of "TickID" is correct... Just no coloring of the row I'm clicking on. WHY????

2) When I delete a row (Click on row, "Menu", "Delete", "OK"), it removes the row and (apparently) the data from the database. But... When I now click on a row below the deleted row, I get the wrong "TickID" - it seems to get the ID from the item in that row before it was deleted. WHY???

I have struggled all day with this and can not figure out what is going on... I need the help of someone a bit smarter than me. I know there's a lot of them on this forum...

Please help!
 

Attachments

A reference is getting cleared in the system. Adding the code below will correct the issue. Place the following two lines of code as the first two lines in the [RunTickList] Sub. You don't need to change any other code, just add the following.

B4X:
Expand Collapse Copy
pnlTickList.LoadLayout("pnlTickList")
tlpnlMenu.Visible=False
 
Last edited:
Upvote 0
Thanks Margret!!!!

Works like a charm!

You deserve a box of chocolates... or a bunch of flowers!

Now I'm trying to figure out the logic behind it...
 
Upvote 0
Hi jpvniekerk,
I wouldn't use margrets' suggestion, because every time you run RunTickList you add a layout increasing the number of views. Loading a new layout doesn't remove the previous one but adds it. That means if you delete 10 items you have the 11 layers of the same layout.

The problem you had is that every time you run RunTickList you add new views to the existing ones. So you can either do:
- remove all the views of the header and of the ScrollView.Panel. before a new populating.
B4X:
Expand Collapse Copy
Sub RunTickList
    
    If tlpnlScrollViewHeader1.NumberOfViews > 0 Then
        For i = 0 To tlpnlScrollViewHeader1.NumberOfViews - 1
            tlpnlScrollViewHeader1.RemoveViewAt(0)
        Next
    End If
    If tlScrollView1.Panel.NumberOfViews > 0 Then
        For i = 0 To tlScrollView1.Panel.NumberOfViews - 1
            tlScrollView1.Panel.RemoveViewAt(0)
        Next
    End If
- use the method described in the User's Guide Edition1.1 page 26
Here we move the content of the labels of the next row to the current row beginning at the row to delete. Then we remove only the labels of the last row.

The second method looks more complicated but is the most efficient one.

Best regards.
 
Last edited:
Upvote 0
Thanks Klaus

I will be adding more functions (filters and sort options) to the program, so I think the more universal approach will be to clear all the view before I repopulate it - as per your first recommendation.

I have made this change to the program and it works perfectly. Thanks again.
 
Upvote 0
Top