Android Question B4XTable

Terradrones

Active Member
Licensed User
Hi All

Me again!

I am using the B4XTable to display my Coordinates, Strings, Tin Model, Terrace, etc. in a B4XTable. I can highlight a Row in the Table and erase it if so required. If I cancel the confirmation to erase the selected Row, then the Row gets "Un-Highlighted".

Here is my problem:

If I highlight a Row and move to the next page, the Row is still highlighted. How do I "Un-Highlight" a Row when moving to the next Page in the Table?

Thanks
Michael
 

Terradrones

Active Member
Licensed User
Here is my code:

B4X:
[/
#Region ********************************************************* List Strings ***********************************************

Sub ShowStringTable
    SV1.Clear
    SV1.DefaultDataFormatter.GetDefaultFormat.GroupingCharacter = ""
    SV1.DefaultDataFormatter.GetDefaultFormat.MinimumFractions = 3
    SV1.AddColumn("Name", SV1.COLUMN_TYPE_TEXT)
    SV1.AddColumn("S\East", SV1.COLUMN_TYPE_NUMBERS)
    SV1.AddColumn("S\North", SV1.COLUMN_TYPE_NUMBERS)
    SV1.AddColumn("S\Elevation", SV1.COLUMN_TYPE_NUMBERS)
    SV1.AddColumn("E\East", SV1.COLUMN_TYPE_NUMBERS)
    SV1.AddColumn("E\North", SV1.COLUMN_TYPE_NUMBERS)
    SV1.AddColumn("E\Elevation", SV1.COLUMN_TYPE_NUMBERS)
    SV1.AddColumn("Stake", SV1.COLUMN_TYPE_NUMBERS)
    SV1.AddColumn("Width", SV1.COLUMN_TYPE_NUMBERS)
    SV1.AddColumn("Radius", SV1.COLUMN_TYPE_NUMBERS)
    SV1.AddColumn("Grade", SV1.COLUMN_TYPE_NUMBERS)
    SV1.AddColumn("Opt", SV1.COLUMN_TYPE_NUMBERS)
    
    Dim Data As List
    Data.Initialize
    OpenString
    Dim rs As ResultSet = CGlobals.sql1.ExecQuery("SELECT StringName, EastSt, NorthSt, ElevationSt, EastEd, NorthEd, ElevationEd, Stake, Width, Radius, Grade, Opt FROM Strings")

    Do While rs.NextRow
        Dim row(12) As Object
        row(0) = rs.GetString("StringName")
        row(1) = NumberFormat2(rs.GetDouble("EastSt"),1,3,3,False)
        row(2) = NumberFormat2(rs.GetDouble("NorthSt"),1,3,3,False)
        row(3) = NumberFormat2(rs.GetDouble("ElevationSt"),1,3,3,False)
        row(4) = NumberFormat2(rs.GetDouble("EastEd"),1,3,3,False)
        row(5) = NumberFormat2(rs.GetDouble("NorthEd"),1,3,3,False)
        row(6) = NumberFormat2(rs.GetDouble("ElevationEd"),1,3,3,False)
        row(7) = NumberFormat2(rs.GetDouble("Stake"),1,3,3,False)
        row(8) = NumberFormat2(rs.GetDouble("Width"),1,3,3,False)
        row(9) = NumberFormat2(rs.GetDouble("Radius"),1,3,3,False)
        row(10) = NumberFormat2(rs.GetDouble("Grade"),1,3,3,False)
        row(11) = NumberFormat2(rs.GetDouble("Opt"),0,0,0,False)
        Data.Add(row)
    Loop
    rs.Close
    SV1.SetData(Data)
    EraseListString.Visible = False
End Sub

#Region ************************************************* Erase Row ********************************************

Sub SV1_CellClicked (ColumnId As String, RowId As Long)
    Dim RowData As Map = SV1.GetRow(RowId)
    
    If PreRowID1>0 Then
        B4XTable1_DataUpdated(PreRowID1, xui.Color_White)
    End If
    If ColumnId <> "Name" Then
        EraseListString.Visible = False
        Return
    End If
    EraseListString.Visible = True
    RowId1=RowId
    Cell= RowData.Get(ColumnId)
    B4XTable1_DataUpdated(RowId, xui.Color_Red)
    PreRowID1=RowId1
End Sub

Sub B4XTable1_DataUpdated(RowIndex As Int, Clr As Int)
    For i = 0 To SV1.VisibleRowIds.Size - 1
        Dim RowId As Long = SV1.VisibleRowIds.Get(i)
        If RowId = RowIndex Then
            SetRowColor(i, Clr)
            Continue
        End If
        If i Mod 2 = 0 Then
            SetRowColor(i, SV1.EvenRowColor)
        Else
            SetRowColor(i, SV1.OddRowColor)
        End If
    Next
End Sub

Sub SetRowColor (RowIndex As Int, Clr As Int)
    For Each c As B4XTableColumn In SV1.VisibleColumns
        Dim pnl As B4XView = c.CellsLayouts.Get(RowIndex + 1) '+1 because of the header
        pnl.Color = Clr
    Next
End Sub

Sub EraseListString_Click
    Dim sf As Object = xui.Msgbox2Async("Sure To Erase " & Cell & "?", "Erase String", "Yes", "Cancel", "", Null)
    Wait For (sf) Msgbox_Result (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        DeleteRow(SV1, RowId1)
    Else
        EraseListString.Visible = False
        B4XTable1_DataUpdated(RowId1, xui.Color_White)
    End If
End Sub

Sub DeleteRow (tbl As B4XTable, RowId As Long)
    Dim RowData As Map = tbl.GetRow(RowId)
    Dim StringName As String = RowData.Get("StringName")
        
    tbl.sql1.ExecNonQuery2("DELETE FROM Data WHERE rowid = ?", Array (RowId))     'deletes record from Table
        
    CGlobals.SQL1.ExecNonQuery2("DELETE FROM Strings WHERE StringName = ?", Array (StringName))  'deletes from DB
    B4XTable1_DataUpdated(RowId1, xui.Color_White)
    
    Dim page As Int = tbl.CurrentPage
    Dim FirstIndex As Int = tbl.FirstRowIndex
    tbl.ClearDataView 'Updates the rows count.
    If FirstIndex + 1 >= tbl.mCurrentCount Then
        page = page - 1
    End If
    tbl.CurrentPage = page
End Sub

#End Region

#End Region
]
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…