Hi group, another little problem. I have a listBox, on a cell I have the color I need stored as text in the form &h00FF0000. I wanted to read it in the PaintCellBackGround to give the color to the line, and I wrote:
if column=2 Then
messagebox ListBoxTipologie.CellTextAt(row,column)
if ListBoxTipologie.CellTextAt(row,column)<>“” then
g.DrawingColor= color.FromString(ListBoxTipologie.CellTextAt(row,column)) ‘E’ il colore scritto
else
g.DrawingColor= &cFFFFFF 'WHITE
end if
g.FillRectangle(0, 0, g.Width, g.Height)
end if
If I had to take a guess (you didn’t include the error you’re getting), it’s because the row and column don’t exist on one of the paint operations.
Try adding a test to ensure you’re within the bounds of your listbox.
if column=2 Then
if row <= me.LastRowIndex and column <= me.LastColumnIndex and ListBoxTipologie.CellTextAt(row,column)<>"" then
g.DrawingColor= color.FromString(ListBoxTipologie.CellTextAt(row,column)) '‘E’ il colore scritto
else
g.DrawingColor= &cFFFFFF 'WHITE
end if
g.FillRectangle(0, 0, g.Width, g.Height)
Return True
end if
You can use the CellTagAt to store the color as a variant.
Then in the PaintCellBackground load the variant as a color:
//Only adding color to the first column
//Make sure rows exist, and that row is not > lastrowindex
If column <> 0 Or Me.RowCount = 0 Or row > Me.LastRowIndex Then
Exit
End If
Var v As Variant = Me.CellTagAt(row,0)
//Make sure v Is Not Nul
If v.IsNull Then Exit
//make sure the data type is a color
If v.Type <> 16 Then Exit
Var c As Color = v
g.DrawingColor = c
g.FillRectangle(0, 0, g.Width, g.Height)