It works for me. Look at my code my manWhen are you told to write in a different colour when the value is greater than 1?
Private formatter As B4XFormatter
CreateCustomFormat(B4XTable1.GetColumn("Student_Num"))
formatter.GetDefaultFormat.TextColor = xui.Color_Black
Private Sub CreateCustomFormat (c As B4XTableColumn)
formatter.Initialize
c.Formatter = formatter
Dim Positive As B4XFormatData = c.Formatter.NewFormatData
Positive.TextColor = xui.Color_Red
' Positive.TextColor = B4XTable1.TextColor
Positive.FormatFont = xui.CreateDefaultFont(22)
c.Formatter.AddFormatData(Positive, 114.01, c.Formatter.MAX_VALUE, True) 'change your 114.01 to 1.01
End Sub
Sub ShowContent( llrows As List )
Dim col0, col1, col2, col3, col4, col5, col6 As B4XTableColumn
'
col0 = tbVC.AddColumn("id",tbVC.COLUMN_TYPE_NUMBERS)
col1 = tbVC.AddColumn("nombre",tbVC.COLUMN_TYPE_TEXT)
col2 = tbVC.AddColumn("estado",tbVC.COLUMN_TYPE_TEXT)
col3 = tbVC.AddColumn("creado",tbVC.COLUMN_TYPE_TEXT)
col4 = tbVC.AddColumn("observaciones",tbVC.COLUMN_TYPE_TEXT)
col5 = tbVC.AddColumn("cantidad",tbVC.COLUMN_TYPE_TEXT)
CreateCustomFormat(col5)
col6 = tbVC.AddColumn("nombresintildes",tbVC.COLUMN_TYPE_TEXT)
col0.Width = -1
col1.Width = tbVC.mBase.Width * 0.40
col2.Width = tbVC.mBase.Width * 0.10
col3.Width = tbVC.mBase.Width * 0.10
col4.Width = tbVC.mBase.Width * 0.30
col5.Width = tbVC.mBase.Width * 0.10
col6.Width = -1
'
For Each tc As B4XTableColumn In Array(col0,col2,col3,col5)
tc.Searchable = False
Next
'
tbVC.Refresh
tbVC.SearchField.RequestFocusAndShowKeyboard
'
tbVC.SetData(llrows)
End Sub
Private Sub CreateCustomFormat (c As B4XTableColumn)
Dim formatter As B4XFormatter
formatter.Initialize
c.Formatter = formatter
' >1
Dim Mayor1 As B4XFormatData = c.Formatter.NewFormatData
Mayor1.TextColor = tbVC.TextColor
Mayor1.FormatFont = xui.CreateDefaultFont(16)
c.Formatter.AddFormatData(Mayor1, 2, c.Formatter.MAX_VALUE, True)
' <=1
Dim Menor2 As B4XFormatData = c.Formatter.CopyFormatData(Mayor1)
Menor2.TextColor = xui.Color_Green
Menor2.FormatFont = xui.CreateDefaultBoldFont(16)
Menor2.Prefix = "("
Menor2.Postfix = ")"
c.Formatter.AddFormatData(Menor2,c.Formatter.MIN_VALUE,1, False)
End Sub
I am pretty sure the formatting applies to NUMBERS columns like this:col5 = tbVC.AddColumn("cantidad",tbVC.COLUMN_TYPE_TEXT)
col5 = tbVC.AddColumn("cantidad",tbVC.COLUMN_TYPE_NUMBERS)
I checked and it has to be NUMBERS and not set up as TEXT when you prepare the columns. It has to be after all the columns are defined, not between col5 and col6Nor does it![]()
CreateColorFormat(B4XTable1.GetColumn("candidad"), Colors.Magenta) 'line after setting data type. the column MUST be of type NUMBERS
Sub CreateColorFormat (c As B4XTableColumn, clr As Int )
Dim formatter As B4XFormatter
formatter.Initialize
c.Formatter = formatter
c.Formatter.GetDefaultFormat.TextColor =clr
End Sub
Sub ShowVerContent( llrows As List )
Dim col0, col1, col2, col3, col4, col5, col6 As B4XTableColumn
col0 = tbVC.AddColumn("id",tbVC.COLUMN_TYPE_NUMBERS)
col1 = tbVC.AddColumn("nombre",tbVC.COLUMN_TYPE_TEXT)
col2 = tbVC.AddColumn("estado",tbVC.COLUMN_TYPE_TEXT)
col3 = tbVC.AddColumn("creado",tbVC.COLUMN_TYPE_TEXT)
col4 = tbVC.AddColumn("observaciones",tbVC.COLUMN_TYPE_TEXT)
col5 = tbVC.AddColumn("cantidad",tbVC.COLUMN_TYPE_NUMBERS)
col6 = tbVC.AddColumn("nombresintildes",tbVC.COLUMN_TYPE_TEXT)
' CreateCustomFormat(col5)
CreateColorFormat(tbVC.GetColumn("candidad"), Colors.Magenta) 'line after setting data type. the column MUST be of type NUMBERS
tbVC.Refresh
tbVC.SetData(llrows)
End Sub
Sub CreateColorFormat (c As B4XTableColumn, clr As Int )
Dim formatter As B4XFormatter
formatter.Initialize
c.Formatter = formatter
c.Formatter.GetDefaultFormat.TextColor =clr
End Sub
You are definitely in the right track. Sometimes it is hard when you are not seeing the project in full in front of you. You can wait, hopefully someone will spot it or post a little project using your code for the formatting.Now that works!!!!!
how can I make it change colour only when the value is greater than 1
CreateCustomFormat(B4XTable1.GetColumn("cantidad"))
formatter.GetDefaultFormat.TextColor = xui.Color_Black 'you need this line too
Private Sub CreateCustomFormat (c As B4XTableColumn)
Dim formatter As B4XFormatter
formatter.Initialize
c.Formatter = formatter
Dim Positive As B4XFormatData = c.Formatter.NewFormatData
Positive.TextColor = xui.Color_Red
' Positive.TextColor = B4XTable1.TextColor
Positive.FormatFont = xui.CreateDefaultFont(22)
c.Formatter.AddFormatData(Positive, 2, c.Formatter.MAX_VALUE, True) 'this is for 2 and bigger. Change it to your minimum
End Sub
You need to declare it in globalsformatter? But that gives error, what is formatter there?
Private formatter As B4XFormatter 'so it is recognized in another sub
It works for me. Look at my code my manWhen are you told to write in a different colour when the value is greater than 1?
Private formatter As B4XFormatter
CreateCustomFormat(B4XTable1.GetColumn("Student_Num"))
formatter.GetDefaultFormat.TextColor = xui.Color_Black
Private Sub CreateCustomFormat (c As B4XTableColumn)
formatter.Initialize
c.Formatter = formatter
Dim Positive As B4XFormatData = c.Formatter.NewFormatData
Positive.TextColor = xui.Color_Red
' Positive.TextColor = B4XTable1.TextColor
Positive.FormatFont = xui.CreateDefaultFont(22)
c.Formatter.AddFormatData(Positive, 114.01, c.Formatter.MAX_VALUE, True) 'change your 114.01 to 1.01
End Sub
I now understand how it works