Hi group, I’m trying to do something at the limit of my possibilities I inserted the color values in the RowTag of a ListBox, which I should use to color the rows of the ListBox separately, line by line.
When I read the data I upload my values:
Then I would like to take these values and color the rows, both with the backcolor and text color. But I can’t … I don’t know what the problem is, I understood that the data is read not in loop but almost.
' RowTag of ROW
Var tag As String = ListBoxEventi.RowTagAt(row)
' IF RowTag is not NULL, separate my values
If tag <> "" Then
Var colori() As String = tag.Split(",")
' BackGround color (ColoreRigo)
If UBound(colori) >= 0 Then
g.FillColor = Color.FromString(colori(0)) ' Colore di sfondo (ColoreRigo)
g.FillRect(0, 0, Me.CellWidth(row, column), Me.CellHeight(row, column))
End If
' TEXTCOLOR (ColoreTesto)
If UBound(colori) >= 1 Then
g.ForeColor = Color.FromString(colori(1)) ' Colore del testo (ColoreTesto)
End If
End If
' DRWA TEXT IN CELL
g.DrawText(Me.Cell(row, column), 5, 5)
Where is your PaintCellText event handler? What does it do?
I have code like this in mine to control what the text looks like:
mrd = me.RowTagAt(row)
if (mrd.outmsg=0 or mrd.tabmboxid=app.outMboxid) then // Style mail as normal
setItalic = False
rowColour = if (pale=True, &c808080, &c000000) // Choose colour intensity
else // Mail to show as visibly an outmail
setItalic = True // Style mail as an Out mail
rowColour = if (pale=True, &ccc8080, &cc00000)
end if
g.Bold = False
g.FontName = "Arial"
g.Italic = setItalic
g.DrawingColor = rowColour
Return False
Now I can color the bottom of the line, but not the character:
If row >= 0 And row < ListBoxEventi.LastRowIndex Then
Var tag As String = ListBoxEventi.RowTagAt(row)
' IF RowTag is not NULL, separate my values
If tag <> "" Then
Var colori() As String = tag.Split(",")
g.Bold=True
g.DrawingColor = Color.FromString(colori(1)) 'colore cella
g.ForeColor = Color.FromString(colori(0)) ' Colore del testo (ColoreTesto)
End If
else
g.DrawingColor= &cFFFFFF 'WHITE
end if
g.FillRectangle(0, 0, g.Width, g.Height)
Return True
If this can help… It’s in the PaintCellText event of the listbox. The color is stored in a hidden listbox column as a string like “&h00FF2B10”
Function PaintCellText(g as Graphics, row as Integer, column as Integer, x as Integer, y as Integer) Handles PaintCellText as Boolean
Var tmp As String = DataList.CellTextAt(row,DL_ColorColumn) // the color is stored in each record
If tmp = "" Then
tmp="&c00000000"
End If
g.ForeColor=Color.FromString(tmp)
End Function
Ok, I think I solved it… for the background color I put the code in PaintCellBackGround
' RowTag of ROW
If row >= 0 And row < ListBoxEventi.LastRowIndex+1 Then
Var tag As String = ListBoxEventi.RowTagAt(row)
' IF RowTag is not NULL, separate my values
If tag <> "" Then
Var colori() As String = tag.Split(",")
g.DrawingColor=Color.FromString(colori(0))
g.FillRectangle(0, 0, g.Width, g.Height)
End If
else
g.DrawingColor= color.White 'WHITE
end if
g.FillRectangle(0, 0, g.Width, g.Height)
return True
for the text color in PaintCelltext.
' RowTag of ROW
If row >= 0 And row < ListBoxEventi.LastRowIndex+1 Then
Var tag As String = ListBoxEventi.RowTagAt(row)
' IF RowTag is not NULL, separate my values
If tag <> "" Then
Var colori() As String = tag.Split(",")
g.Bold=True
g.ForeColor = Color.FromString(colori(1)) ' Colore del testo (ColoreTesto)
End If
else
g.ForeColor = color.Black ' Colore del testo (ColoreTesto)
end if