I have a combo box that is populated by an sql statement. If a field is 1 I want the color of the item added to be Green, if it is 0 I want the color of the item to be white. I would prefer the background of each item to change colors but I will settle for just the text color of each item. Is this possible?
Dim lstItems As List
lstItems.Initialize
Dim rs As ResultSet
Do While rs.NextRow
If rs.GetString("n").Contains("1") Then
lstItems.Add(cs.Initialize.Color(Colors.Green).Append(rs.GetString("n")).PopAll)
Else
lstItems.Add(cs.Initialize.Color(Colors.Red).Append(rs.GetString("n")).PopAll)
End If
Loop
rs.close
B4XComboBox1.SetItems(lstItems)
Yes. You can use CSBuilder when you build your list items. See example:
lstItems.Initialize
B4X:
Dim cs As CSBuilder
lstItems.AddAll(Array As Object(cs.Initialize.Color(xui.Color_Red).Append("Dog").PopAll, _
cs.Initialize.Color(xui.Color_Magenta).Append("Cat").PopAll, "Bird", "Camel", "Tiger", "Elephant"))
Of course you replace the cats and dogs with rs.getstring("col")
Dim lstItems As List
lstItems.Initialize
Dim rs As ResultSet
Do While rs.NextRow
If rs.GetString("n").Contains("1") Then
lstItems.Add(cs.Initialize.Color(Colors.Green).Append(rs.GetString("n")).PopAll)
Else
lstItems.Add(cs.Initialize.Color(Colors.Red).Append(rs.GetString("n")).PopAll)
End If
Loop
rs.close
B4XComboBox1.SetItems(lstItems)