Bug? Problem with TableView add from variable.

Gary Miyakawa

Active Member
Licensed User
This one is odd (or, I just don't understand).

I've built a small 2 column (default) tableview. I then add 3 items to it from an array. That array of elements was created from a Regex split. If I add the items directly from the split, All is good BUT if I move the values of those items to another matching string array, only the last value gets added to all the rows in the Tableview.

B4X:
    TableView1.SetColumns(Array As String("Site Name", "IP Address"))
    line = "HDX Desk"", ""10.1.2.86:24""" & CRLF & "Group Series"", ""10.1.2.50:24""" & CRLF & "Callback 157"", ""171.1.2.157:24""" & CRLF

    lines = Regex.Split(CRLF, line)            'Split the lines based on CRLF

    For Each item In lines
         items = Regex.Split(",", item)        'Split the line based on Comma
        test(0) = items(0)                    'move value from one array to another
        Log("Added: " & test(0))            'Show it's value in the log
   
        test(1) = items(1)
        Log("Added: " & test(1))
       
        TableView1.Items.Add(test)            'add the 'test' string array to the tableview
    Next
I have my get around but I'm trying to understand if this is a BUG or a misunderstanding on my part.

I've included the .zip of the application.

Anyone that can help me understand this would be greatly appreciated.

Gary Miyakawa
 

Attachments

rwblinn

Well-Known Member
Licensed User
Hi,

for every row you need to use a new array. Try:

B4X:
For Each item In lines
  Dim row(2) As String
  row = Regex.Split(",", item)        'Split the line based on Comma
  TableView1.Items.Add(row)         'Add the string array to the tableview
Next
One other. You could simplify the string:
B4X:
line = "HDX Desk,10.1.2.86:24" & CRLF & "Group Series,10.1.2.50:24" & CRLF & "Callback 157,171.1.2.157:24"
 

Gary Miyakawa

Active Member
Licensed User
Hi,

for every row you need to use a new array. Try:

B4X:
For Each item In lines
  Dim row(2) As String
  row = Regex.Split(",", item)        'Split the line based on Comma
  TableView1.Items.Add(row)         'Add the string array to the tableview
Next
One other. You could simplify the string:
B4X:
line = "HDX Desk,10.1.2.86:24" & CRLF & "Group Series,10.1.2.50:24" & CRLF & "Callback 157,171.1.2.157:24"
Thank you for the reply.

Your solution still doesn't allow me to move the value to the new array (in my case, it's called "test".)... I still get the repetitive issue.

As for simplifying the string, It needs to meet .csv format (which includes the Double quotes around text fields) so that is not an option.

Thank you though !

Gary Miyakawa
 

Daestrum

Well-Known Member
Licensed User
Try
B4X:
    For Each item In lines
        items = Regex.Split(",", item)        'Split the line based on Comma
        Dim test(2) As String
        test(0) = items(0)
        test(1) = items(1)
        Log("Added: " & test(0))            'Show it's value in the log
        Log("Added: " & test(1))
        TableView1.Items.Add(test)            'add the 'test' string array to the tableview
    Next
 

Gary Miyakawa

Active Member
Licensed User
Try
B4X:
    For Each item In lines
        items = Regex.Split(",", item)        'Split the line based on Comma
        Dim test(2) As String
        test(0) = items(0)
        test(1) = items(1)
        Log("Added: " & test(0))            'Show it's value in the log
        Log("Added: " & test(1))
        TableView1.Items.Add(test)            'add the 'test' string array to the tableview
    Next

Thank you! Yes, that does work and fix the issue but Why does the array have to be redefined each time ?

Thanks!

Gary Miyakawa
 
Top