Well.. I'm working on a B4Xtable and I'd like to change X Row according to content.. Ex: I have the column "state" below it shows "Exists" and "Not Exists" and I need to change the row's color if it's "Not Exists" I've seen this post: B4XTable How do I change the color of a row ? and it paints the 5th Table Row . I need something like that but painting the whole row if it's "Not Exists" and then disable that row, I mean can see it but not able to edit it when I cell_click.
Sub B4XTable1_DataUpdated
For i = 0 To B4XTable1.VisibleRowIds.Size - 1
Dim RowId As Long = B4XTable1.VisibleRowIds.Get(i)
If RowId > 0 Then
'criteria
Dim Value As Double = B4XTable1.GetRow(RowId).Get(numberColumn.Id)
If Value > 10 Then
SetRowColor(i, xui.Color_Red)
Continue
End If
End If
If i Mod 2 = 0 Then
SetRowColor(i, B4XTable1.EvenRowColor)
Else
SetRowColor(i, B4XTable1.OddRowColor)
End If
Next
End Sub
Sub SetRowColor (RowIndex As Int, Clr As Int)
For Each c As B4XTableColumn In B4XTable1.VisibleColumns
Dim pnl As B4XView = c.CellsLayouts.Get(RowIndex + 1) '+1 because of the header
pnl.Color = Clr
Next
End Sub
I'm not sure what you mean with "disable that row" however you can store the RowId value in a B4XSet and later use it to determine whether a row is disabled or not.
Sub B4XTable1_DataUpdated
For i = 0 To B4XTable1.VisibleRowIds.Size - 1
Dim RowId As Long = B4XTable1.VisibleRowIds.Get(i)
If RowId > 0 Then
'criteria
Dim Value As Double = B4XTable1.GetRow(RowId).Get(numberColumn.Id)
If Value > 10 Then
SetRowColor(i, xui.Color_Red)
Continue
End If
End If
If i Mod 2 = 0 Then
SetRowColor(i, B4XTable1.EvenRowColor)
Else
SetRowColor(i, B4XTable1.OddRowColor)
End If
Next
End Sub
Sub SetRowColor (RowIndex As Int, Clr As Int)
For Each c As B4XTableColumn In B4XTable1.VisibleColumns
Dim pnl As B4XView = c.CellsLayouts.Get(RowIndex + 1) '+1 because of the header
pnl.Color = Clr
Next
End Sub
I'm not sure what you mean with "disable that row" however you can store the RowId value in a B4XSet and later use it to determine whether a row is disabled or not.
Hey Erel! thank you for help ..! I'll try this code... well when I say "disable row" I mean that row does nothing on cell_click event or long_cell_click event .. In my B4XTable I have a Cell_click event for editing and updating data.
Thank you So Much
Sub B4XTable1_DataUpdated
For i = 0 To B4XTable1.VisibleRowIds.Size - 1
Dim RowId As Long = B4XTable1.VisibleRowIds.Get(i)
If RowId > 0 Then
'criteria
Dim Value As Double = B4XTable1.GetRow(RowId).Get(numberColumn.Id)
If Value > 10 Then
SetRowColor(i, xui.Color_Red)
Continue
End If
End If
If i Mod 2 = 0 Then
SetRowColor(i, B4XTable1.EvenRowColor)
Else
SetRowColor(i, B4XTable1.OddRowColor)
End If
Next
End Sub
Sub SetRowColor (RowIndex As Int, Clr As Int)
For Each c As B4XTableColumn In B4XTable1.VisibleColumns
Dim pnl As B4XView = c.CellsLayouts.Get(RowIndex + 1) '+1 because of the header
pnl.Color = Clr
Next
End Sub
I'm not sure what you mean with "disable that row" however you can store the RowId value in a B4XSet and later use it to determine whether a row is disabled or not.
Hey Erel I've been trying to implement your code without good result. I've changed on line 6 ' the value type to string because my column 'state' it's a string type but I don't understand 'numnercolum.Id' . Can you help with that please? Thank you
Hey Erel I've been trying to implement your code without good result. I've changed on line 6 ' the value type to string because my column 'state' it's a string type but I don't understand 'numnercolum.Id' . Can you help with that please? Thank you
B4XTable.GetRow returns a Map. You need to find the relevant column id. The best way to do it is like I did with numberColumn. You can however also find by logging the map:
B4X:
Log(B4XTable1.GetRow(RowId))
The solution will then be something like:
B4X:
Dim Value As String = BX4Table1.GetRow(RowId).Get("c2")
B4XTable.GetRow returns a Map. You need to find the relevant column id. The best way to do it is like I did with numberColumn. You can however also find by logging the map:
B4X:
Log(B4XTable1.GetRow(RowId))
The solution will then be something like:
B4X:
Dim Value As String = BX4Table1.GetRow(RowId).Get("c2")