B4J Question adding items to a TABLEVIEW

Pelky

Active Member
Licensed User
Longtime User
I was wondering if anyone can shed some light on what is going on here:-

B4X:
Do While bookedCursor.NextRow
        counter = 0
        Dim xRow(6) As Object
        xRow(0) = bookedCursor.GetString("InMate")
        xRow(1) = bookedCursor.GetString("Cell")
        xRow(2) = bookedCursor.GetString("TimeOfDay")
        xRow(3) = bookedCursor.GetString("Visitor")
        xRow(4) = bookedCursor.GetString("Occupation")
        xRow(5) = bookedCursor.GetString("TypeOfBooking")
        If DateTime.Date(bookedCursor.GetString("BookingsDate")) = DateTime.Date(ReportDate) Then
            RegisterView.Items.Add(xRow)
            Dim ar() As String = Regex.Split(",",xRow(3))
            For Each m As String In ar
                counter = counter +1
                If counter > 1 Then
                    xRow(0) = " "
                    xRow(1) = " "
                    xRow(2) = " "
                    xRow(3) = m
                    Log(m)
                    xRow(4) = " "
                    xRow(5) = " "
                    RegisterView.Items.Add(xRow)
                End If
            Next
        End If   
            counter = 0   
    Loop

what I am trying to do is create a view of all records of a specified date and criteria. once I have a record I then add it
to the tableview. ONE of the fields can contain a few visitors separated by a comma. The regex.spilt separates them into
an array. I skip the first occurrence as I want full detail in the line. If there is more than one then I want to blank out the
detail and only show the string from the split.
The Log(m) shows each split field lovely however when I add the row to the table it shows only the last occurrence a number
of times and blanks the detail section. It adds the correct number of entries but looks like the items.add seems to overwrite the
previous entry.
1643976906022.png


what it looks like without the regex.split... you will notice the second line shows detail and the visitor column with commas.

1643977043913.png


this is the output with the split. As you can see the second line detail has gone and the last occurrence of the split is shown
multiple times.

I have tried creating a subroutine that waits to complete but that just duplicates the entries and I get 6 entries on the table.

Any assistance would be appreciated
 

Pelky

Active Member
Licensed User
Longtime User
I was wondering if anyone can shed some light on what is going on here:-

B4X:
Do While bookedCursor.NextRow
        counter = 0
        Dim xRow(6) As Object
        xRow(0) = bookedCursor.GetString("InMate")
        xRow(1) = bookedCursor.GetString("Cell")
        xRow(2) = bookedCursor.GetString("TimeOfDay")
        xRow(3) = bookedCursor.GetString("Visitor")
        xRow(4) = bookedCursor.GetString("Occupation")
        xRow(5) = bookedCursor.GetString("TypeOfBooking")
        If DateTime.Date(bookedCursor.GetString("BookingsDate")) = DateTime.Date(ReportDate) Then
            RegisterView.Items.Add(xRow)
            Dim ar() As String = Regex.Split(",",xRow(3))
            For Each m As String In ar
                counter = counter +1
                If counter > 1 Then
                    xRow(0) = " "
                    xRow(1) = " "
                    xRow(2) = " "
                    xRow(3) = m
                    Log(m)
                    xRow(4) = " "
                    xRow(5) = " "
                    RegisterView.Items.Add(xRow)
                End If
            Next
        End If  
            counter = 0  
    Loop

what I am trying to do is create a view of all records of a specified date and criteria. once I have a record I then add it
to the tableview. ONE of the fields can contain a few visitors separated by a comma. The regex.spilt separates them into
an array. I skip the first occurrence as I want full detail in the line. If there is more than one then I want to blank out the
detail and only show the string from the split.
The Log(m) shows each split field lovely however when I add the row to the table it shows only the last occurrence a number
of times and blanks the detail section. It adds the correct number of entries but looks like the items.add seems to overwrite the
previous entry.
View attachment 125105

what it looks like without the regex.split... you will notice the second line shows detail and the visitor column with commas.

View attachment 125106

this is the output with the split. As you can see the second line detail has gone and the last occurrence of the split is shown
multiple times.

I have tried creating a subroutine that waits to complete but that just duplicates the entries and I get 6 entries on the table.

Any assistance would be appreciated
If anyone is interested I have managed to resolve this problem. Although it has been resolved it does not mean I understand why.
What I did was to create (Dim) another object and use that the add to the tableview.
B4X:
            For Each m As String In ar
                counter = counter +1
                If counter > 1 Then
                    Dim yRow(6) As Object
                    yRow(0) = " "
                    yRow(1) = " "
                    yRow(2) = m
                    yRow(3) = " "
                    yRow(4) = " "
                    yRow(5) = " "
                    GateTableView.Items.Add(yRow)
                End If
            Next

it would be nice if someone could explain this for me as I would have not have expected to have to do this.

Anyway I hope this has helped anyone else with a similar problem.
 
Upvote 0
Top