Wish B4XTableSelections - Keep existing formatting

MrKim

Well-Known Member
Licensed User
Longtime User
I was so exited when I saw this. It would be rally nice to highlight the selected line.
Unfortunately I am making extensive use of B4XDateFormatter and B4XStringFormatter to format some of the columns (examples below) and I have found that B4XTableSelections strips all of the formatting.
B4X:
'format the start date Red If Start Date is today or late, Yellow if within 3 days
    Dim DFYellow As B4XDateFormatter
    DFYellow.Initialize
    StartDateCol.DateFormatter = DFYellow
    Dim HasAF As B4XDateFormatData = StartDateCol.DateFormatter.NewFormatData
    HasAF.TextColor = XUI.Color_Yellow
    HasAF.BackColor = 0  ' xui.Color_White
    HasAF.FormatFont = XUI.CreateDefaultBoldFont(UnSchedOpsList.LabelsFont.Size)
    StartDateCol.DateFormatter.AddFormatData(HasAF, True, 4)
    Dim HasAFRed As B4XDateFormatData = StartDateCol.DateFormatter.CopyFormatData(HasAF)
    HasAFRed.TextColor = XUI.Color_Red
    StartDateCol.DateFormatter.AddFormatData(HasAFRed, True, 0)

or perhaps someone smarter than me could point me in the right direction so I can modify B4XTableSelections to use my formatting?
As always I want to thank everyone here for your incredible support. B4X has made programming fun again!
 

MrKim

Well-Known Member
Licensed User
Longtime User
Can you create a small example with the formatting and B4XTableSelections?
Here it is with all of my original formatting and some real sample data.
Thanks for taking the time to take a look.
I should mention this is an old code version of B4x tables that I started using years ago and I have modified it but I don't think my mods are anything that would impact this issue. It also throws an error in design: but it has always done that and it seems to work fine and how to fix the error was not obvious to me so I have ignored it. I did try to switch to the B4xlib at one point years ago but again, this generated a lot of errors that I didn't understand or have time to fix and the program works great so I have stuck with this.
Highlighting the selected line is great feature because it 'bookmarks' where you are in the table. I hope it is an easy fix.
 

Attachments

  • B4XTableTest.zip
    30.8 KB · Views: 20

John Naylor

Active Member
Licensed User
Longtime User
Try the attached.

I have modified the B4XTableSelections code to maintain text formatting between Select and De-Select.

The error you see about HighlightTextColor is because the property in the B4XTable class on line 7 does not have a default value.

It was just a case of commenting out 3 lines.


B4X:
Public Sub Refresh
    For i = 0 To mTable.VisibleRowIds.Size - 1
        Dim clr As Int
        If i Mod 2 = 0 Then clr = mTable.EvenRowColor Else clr = mTable.OddRowColor
        Dim RowId As Long = mTable.VisibleRowIds.Get(i)
        Dim RowSelected As Boolean = SelectedLines.ContainsKey(RowId)
        If RowSelected And LineMode = False Then
            Dim SelectedCells As List = SelectedLines.Get(RowId)
        End If
        For Each col As B4XTableColumn In mTable.VisibleColumns
            Dim p As B4XView = col.CellsLayouts.Get(i + 1)
            'Dim lbl As B4XView = p.GetView(col.LabelIndex)
            If RowSelected And (LineMode Or SelectedCells.IndexOf(col.Id) > -1) Then
                p.Color = SelectionColor
                'lbl.TextColor = SelectedTextColor
            Else
                p.Color = clr
'                lbl.TextColor = mTable.TextColor
            End If
        Next
    Next

 

Attachments

  • B4XTableTest.zip
    31.5 KB · Views: 15
Last edited:

MrKim

Well-Known Member
Licensed User
Longtime User
Worked like a charm, thank you. If this wasn't a wish I would mark this as the solution.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…