Android Question b4xTable with buttons

Scantech

Well-Known Member
Licensed User
Longtime User
I am running into an error. I am trying to create edit column like the example provide at the forum. My codes is as following.
B4X:
Sub InitTableandSql(FirstTime As Boolean)
    Try

        If FirstTime Or blnFileAvailable = False Then
            'check external first
            If File.Exists(File.DirRootExternal, Starter.DiagReportDatabase & "diagreport.db") Then
                sql.Initialize(File.DirRootExternal, Starter.DiagReportDatabase & "diagreport.db", False)
                blnFileAvailable = True
            Else If File.Exists(File.DirInternal, Starter.DiagReportDatabase & "diagreport.db") Then
                sql.Initialize(File.DirInternal, Starter.DiagReportDatabase & "diagreport.db", False)
                blnFileAvailable = True
            Else
                blnFileAvailable = False
            End If
        End If
           
        Activity.LoadLayout("diagreporttable")

        'this is for edit and delete button
        editCol = B4XTable1.AddColumn("Edit", B4XTable1.COLUMN_TYPE_TEXT)
        editCol.Sortable = False
        editCol.Width = 127dip
       
        B4XTable1.NumberOfFrozenColumns = 1
       
        B4XTable1.AddColumn("ID", B4XTable1.COLUMN_TYPE_NUMBERS)
        B4XTable1.AddColumn("RO", B4XTable1.COLUMN_TYPE_TEXT)
        B4XTable1.AddColumn("Date", B4XTable1.COLUMN_TYPE_TEXT)
        B4XTable1.AddColumn("VIN", B4XTable1.COLUMN_TYPE_TEXT)
        B4XTable1.AddColumn("Year", B4XTable1.COLUMN_TYPE_TEXT)
        B4XTable1.AddColumn("Make", B4XTable1.COLUMN_TYPE_TEXT)
        B4XTable1.AddColumn("Model", B4XTable1.COLUMN_TYPE_TEXT)
        B4XTable1.AddColumn("File Name", B4XTable1.COLUMN_TYPE_TEXT)
       
        Dim Data As List
        Data.Initialize
       
        If blnFileAvailable = True Then
            Dim rs As ResultSet = sql.ExecQuery("SELECT ID, RO, Date, VIN, Year, Make, Model, FileName FROM diagnosticlog")
            Dim startTime As Long = DateTime.Now
           

            Do While rs.NextRow
                Dim row(8) As Object
                row(0) = rs.GetDouble("ID")
                row(1) = rs.GetString("RO")
                row(2) = rs.GetString("Date")
                row(3) = rs.GetString("VIN")
                row(4) = rs.GetString("Year")
                row(5) = rs.GetString("Make")
                row(6) = rs.GetString("Model")
                row(7) = rs.GetString("FileName")

                If row(0) = Null Then row(0) = ""
                If row(1) = Null Then row(1) = ""
                If row(2) = Null Then row(2) = ""
                If row(3) = Null Then row(3) = ""
                If row(4) = Null Then row(4) = ""
                If row(5) = Null Then row(5) = ""
                If row(6) = Null Then row(6) = ""
                If row(7) = Null Then row(7) = ""
               
                Data.Add(row)
            Loop
            Log("Index time: " & (DateTime.Now - startTime) & " ms")

            rs.Close

            Dim startTime As Long = DateTime.Now

            B4XTable1.SetData(Data)
        '    B4XTable1.MaximumRowsPerPage = 1
       
            For i = 1 To editCol.CellsLayouts.Size - 1
                Dim p As B4XView = editCol.CellsLayouts.Get(i)
                p.AddView(CreateButton("btnEdit", Chr(0xF044)), 2dip, 5dip, 40dip, 40dip)
                p.AddView(CreateButton("btnDelete", Chr(0xF00D)), 44dip, 5dip, 40dip, 40dip)
                p.AddView(CreateButton("btnDuplicate",Chr(0xF0C5)), 85dip, 5dip, 40dip, 40dip)
            Next
           
            Log("Index time: " & (DateTime.Now - startTime) & " ms")
        Else
            'no file..do nothing but show the table
            B4XTable1.SetData(Data)
        End If
    Catch
        Log("Error InitTable and Sql" & LastException.Message)
    End Try
End Sub

If you look at For i = 1 To editCol.CellsLayouts.Size - 1 code. It will trigger B4XTable1_DataUpdated event in my project but the example will not.


B4X:
Private Sub B4XTable1_DataUpdated
    For i = 0 To B4XTable1.VisibleRowIds.Size - 1
        Dim p As B4XView = editCol.CellsLayouts.Get(i + 1)
        p.GetView(1).Visible = B4XTable1.VisibleRowIds.Get(i) > 0
        p.GetView(2).Visible = p.GetView(1).Visible
        p.GetView(3).Visible = p.GetView(1).Visible
    Next
End Sub
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…