1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

Android Question B4XTable shows duplicated columns

Discussion in 'Android Questions' started by Makumbi, Apr 11, 2019.

Thread Status:
Not open for further replies.
  1. Makumbi

    Makumbi Active Member Licensed User

    Please help this is my code i was trying to display Sentmessages but wen i click on sent messages i get these please views as show please help i would want to display only sent messages but when i click on the button it the first time it doesnt show but the second time it shows duplicated columns please help.

    i have attached copy show what happened on the first click (it shows empty empty rows)

    Code:
    Sub ShowTable
        
    If lblSelectedItem.Text="Send" Then
            
    'B4XTable1.Refresh
            B4XTable1.AddColumn("Datesent", B4XTable1.COLUMN_TYPE_TEXT)
            B4XTable1.AddColumn(
    "SentMessage", B4XTable1.COLUMN_TYPE_TEXT)
            B4XTable1.AddColumn(
    "ID", B4XTable1.COLUMN_TYPE_TEXT)

            data.Initialize
            
    Dim rs As ResultSet = Starter.SQL1.ExecQuery("SELECT DISTINCT Datesent,Sms as SentMessage,ID FROM Sentmessages")
            
    Do While rs.NextRow
                
    Dim row(4As Object
                row(
    0) = rs.GetString("Datesent")
                row(
    1) = rs.GetString("SentMessage")
                row(
    2) = rs.GetString("ID")
                
    Log(row(1))
                
    Log(row(3))
                
    Log(row(2))
                
    '& " " & rs.GetString("LastName")
                'row(2) = rs.GetString("ID")
                'Some of the fields are Null. We need to convert them to empty strings:
                If row(1) = "" And  row(2) = "" Then
                    
    Return
                
    Else
                    
    If row(1) = Null Then row(2) = ""
                    row(
    1) = rs.GetString("SentMessage")
          
                    data.Add(row)
                
    End If
          

            
    Loop
            rs.Close
            B4XTable1.SetData(data)
            B4XTable1.Refresh
             
    Return
    Else
        B4XTable1.AddColumn(
    "Datesent", B4XTable1.COLUMN_TYPE_TEXT)
        B4XTable1.AddColumn(
    "SentMessage", B4XTable1.COLUMN_TYPE_TEXT)
        B4XTable1.AddColumn(
    "ID", B4XTable1.COLUMN_TYPE_TEXT)

        data.Initialize
        
    Dim rs As ResultSet = Starter.SQL1.ExecQuery("SELECT DISTINCT Datesent,Sms as SentMessage,ID FROM Sentmessages")
        
    Do While rs.NextRow
            
    Dim row(4As Object
            row(
    0) = rs.GetString("Datesent")
            row(
    1) = rs.GetString("SentMessage")
            row(
    2) = rs.GetString("ID")
            
    Log(row(1))
            
    Log(row(3))
            
    Log(row(2))
            
    '& " " & rs.GetString("LastName")
            'row(2) = rs.GetString("ID")
            'Some of the fields are Null. We need to convert them to empty strings:
            If row(1) = "" And  row(2) = "" Then
                
    Return
                
    Else
                
    If row(1) = Null Then row(2) = ""
                row(
    1) = rs.GetString("SentMessage")
          
                data.Add(row)
            
    End If
          

        
    Loop
        rs.Close
        B4XTable1.SetData(data)
        
    'B4XTable1.Refresh
        End If
    End Sub
    Code:
    Sub btnEdit_Click
        
    'B4XTable1.Clear

        ShowTable
      
        lblSelectedItem.Text=
    "Send"
    End Sub
     

    Attached Files:

    Last edited: Apr 11, 2019
  2. Computersmith64

    Computersmith64 Well-Known Member Licensed User

    So first of all, if you want to check for Null in your ResultSet, you need to use:

    Code:
    If row(1) = "null"
    Secondly, your screenshots don't show the issue you have described in your post. I don't see any duplicated columns.

    - Colin.
     
  3. Makumbi

    Makumbi Active Member Licensed User

    What is displayed has two extension of https://www.b4x.com/android/forum/attachments/screenshot_1554976045-png.79264/ and this
    https://www.b4x.com/android/forum/attachments/screenshot_1554976215-png.79265/ it gives the same columns but with different data out puts but all this is happens when you click on the single buttion
     
  4. DonManfred

    DonManfred Expert Licensed User

    Upload a small project which shows the issue. For everything else it is hard to give any congrete advice. Do NOT forget to include the databasefile.

    Away from that i too do not see any duplicates

    The results are different, yes. But i do not see any duplicates.
     
    Last edited: Apr 11, 2019
  5. Makumbi

    Makumbi Active Member Licensed User

    i have uploaded the compressed project please look at it you see that when the user clicks on sent message it duplicates the columns the first three columns are okay but when you scroll on your right you will see more columns show more informs yet i wanted it to show only three columns . please help.

    2. When you click on received it will not delete other columns of sent messages it will continue show additional columns every time you click on those corresponding buttons

    thanks in advance
     

    Attached Files:

  6. Erel

    Erel Administrator Staff Member Licensed User

    You should only add columns once in Activity_Create. Your code adds the columns many times.
     
    mangojack likes this.
  7. Makumbi

    Makumbi Active Member Licensed User

    i have removed it as per your suggestion but still when i click on the sent button i see more columns
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    I can only say that you are still doing something wrong. You should create a preferably small project with the updated code and upload it.
     
  9. Makumbi

    Makumbi Active Member Licensed User

    That is the new upload after collection what you suggested thanks
     

    Attached Files:

  10. Erel

    Erel Administrator Staff Member Licensed User

    Same answer as before: you should only add columns once in Activity_Create. Your code adds the columns many times.

    I'm locking this thread. It is not fair for other members who try to help you that you don't follow our advice...
     
    Computersmith64 and DonManfred like this.
Thread Status:
Not open for further replies.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice