Android Question Make Text bold inside b4x table

i have type a text inside a row of b4x table like column(2) = "total". but i need to make this text as bold. is it possible?
 

Mahares

Expert
Licensed User
Longtime User
i have type a text inside a row of b4x table like column(2) = "total". but i need to make this text as bold. is it possible?
It is not clear from your question what text you wanted to make bold (data?, header?). You need to enter some code show a snapshot of of the table part that is supposed to be bold.
 
Upvote 0

GJREDITOR

Member
i have type a text inside a row of b4x table like column(2) = "total". but i need to make this text as bold. is it possible?
If you want to make the entire column bold, you can use this code (courtesy Mahare's answer in forum):
make text bold in b4xtable column:
I use this in my b4xtable:
'neetmarks = tbl1.AddColumn("NEET MARKS", tbl1.COLUMN_TYPE_NUMBERS)
Dim c As B4XTableColumn= neetmarks
        For i = 1 To c.CellsLayouts.Size - 1
            Dim pnl As B4XView = c.CellsLayouts.Get(i)
            Dim lbl As B4XView = pnl.GetView(0)
            lbl.Font = xui.CreateDefaultBoldFont(20)
        Next
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Full code to set entire column:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Dim c1 As B4XTableColumn = B4XTable1.AddColumn("Col 1", B4XTable1.COLUMN_TYPE_TEXT)
    B4XTable1.AddColumn("Col 2", B4XTable1.COLUMN_TYPE_NUMBERS)
    Dim data As List
    data.Initialize
    For i = 1 To 100
        data.Add(Array("Item #" & i, i))
    Next
    B4XTable1.MaximumRowsPerPage = 20
    B4XTable1.BuildLayoutsCache(B4XTable1.MaximumRowsPerPage)
    For i = 1 To c1.CellsLayouts.Size - 1 'skipping the header
        Dim pnl As B4XView = c1.CellsLayouts.Get(i)
        pnl.GetView(c1.LabelIndex).Font = xui.CreateDefaultBoldFont(16)
    Next
    B4XTable1.SetData(data)
End Sub


If you have a table made of a single page then you can make a specific row bold easily. If more than one page then you need to handle the DataUpdated event and change the style there.
 
Upvote 0
Full code to set entire column:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Dim c1 As B4XTableColumn = B4XTable1.AddColumn("Col 1", B4XTable1.COLUMN_TYPE_TEXT)
    B4XTable1.AddColumn("Col 2", B4XTable1.COLUMN_TYPE_NUMBERS)
    Dim data As List
    data.Initialize
    For i = 1 To 100
        data.Add(Array("Item #" & i, i))
    Next
    B4XTable1.MaximumRowsPerPage = 20
    B4XTable1.BuildLayoutsCache(B4XTable1.MaximumRowsPerPage)
    For i = 1 To c1.CellsLayouts.Size - 1 'skipping the header
        Dim pnl As B4XView = c1.CellsLayouts.Get(i)
        pnl.GetView(c1.LabelIndex).Font = xui.CreateDefaultBoldFont(16)
    Next
    B4XTable1.SetData(data)
End Sub


If you have a table made of a single page then you can make a specific row bold easily. If more than one page then you need to handle the DataUpdated event and change the style there.

I need to make the text "total" only as bold and no need to bold any other text
 

Attachments

  • Screenshot_20230808-115142.png
    Screenshot_20230808-115142.png
    78.5 KB · Views: 55
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I need to make the text "total" only as bold and no need to bold any other text
You can have something like this:
B4X:
Private c1 As B4XTableColumn   'in Class_Global
B4X:
c1 = B4XTable1.AddColumn("Account Name", B4XTable1.COLUMN_TYPE_TEXT)  ' in B4XPage_Created
B4X:
Sub B4XTable1_DataUpdated    
    For i = 0 To B4XTable1.VisibleRowIds.Size - 1
            Dim pnl As B4XView = c1.CellsLayouts.Get(i+1) 
            If pnl.GetView(c1.LabelIndex).Text="Total" Then 
'            If pnl.GetView(c1.LabelIndex).Text.Contains("Total") Then 
                  pnl.GetView(c1.LabelIndex).Font = xui.CreateDefaultBoldFont(32)
            Else
                  pnl.GetView(c1.LabelIndex).Font = xui.CreateDefaultFont(16)
            End If
        Next
End Sub
 
Upvote 0
You can have something like this:
B4X:
Private c1 As B4XTableColumn   'in Class_Global
B4X:
c1 = B4XTable1.AddColumn("Account Name", B4XTable1.COLUMN_TYPE_TEXT)  ' in B4XPage_Created
B4X:
Sub B4XTable1_DataUpdated
    For i = 0 To B4XTable1.VisibleRowIds.Size - 1
            Dim pnl As B4XView = c1.CellsLayouts.Get(i+1)
            If pnl.GetView(c1.LabelIndex).Text="Total" Then
'            If pnl.GetView(c1.LabelIndex).Text.Contains("Total") Then
                  pnl.GetView(c1.LabelIndex).Font = xui.CreateDefaultBoldFont(32)
            Else
                  pnl.GetView(c1.LabelIndex).Font = xui.CreateDefaultFont(16)
            End If
        Next
End Sub
It Worked. Thanks Mr. Mahares.
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Can I able to convert the the text "total" and number in nearby column As bold
Yes, For the total value (number) keep track of a global variable of the sum and use B4XFormatter to format the total value.
B4X:
Private Sub CreateCustomFormat (c As B4XTableColumn)
   'code to add the formatter
End sub
Call it like this after you populate the table:
B4X:
B4XTable1.SetData(data)
CreateCustomFormat (B4XTable1.GetColumn("Debit Amount"))
If you need help and you are able to post a small project or your code to populate the table, come back.
Here is an example of what it would like:
1691704095451.png
 
Last edited:
Upvote 0
Top