Problem in PaintCellBackground

Hello group, I would like to color the line in which a condition occurs with EvidenziaLine=true, but I can only color the cell … The problem certainly depends on PaintCellBackGround, because from what I understand here a reading is repeated for each line, and therefore the EvidenziaRigo=False is read to me on restart and therefore I only color the cell in which EvidenziaRigo=true. I hope I made myself clear. How can I do to color the whole staff?


Dim EvidenziaRigo as Boolean
EvidenziaRigo=False



if (row>=2 and row<=ListBoxIngressi.RowCount-1) and (column=6 or column=9) then
  messagebox "LEggo "+ listboxingressi.CellTextAt(row,6)
  Var d1 As DateTime
  Var d2 As DateTime
  Var ActualDate as datetime=DateTime.Now
  
  if listboxingressi.CellTextAt(row,6)<>"" then
    d1 = ConvertToDateTime(listboxingressi.CellTextAt(row,6)) '1° Rata
    if ActualDate>d1 and listboxingressi.CellTextAt(row,8)="False" then  '8=Pagata?
      messagebox ActualDate.SQLDate + " > " + d1.SQLDate + " and " + listboxingressi.CellTextAt(row,8)
      EvidenziaRigo=true
    else
      messagebox ActualDate.SQLDate + " < " + d1.SQLDate + " and " + listboxingressi.CellTextAt(row,8)
      EvidenziaRigo=False
      
      
      if listboxingressi.CellTextAt(row,9)<>"" then
        d2 = ConvertToDateTime(listboxingressi.CellTextAt(row,9)) '2° Rata
        if ActualDate>d2 and listboxingressi.CellTextAt(row,11)="False" then  '11=Pagata?
          messagebox ActualDate.SQLDate + " > " + d2.SQLDate + " and " + listboxingressi.CellTextAt(row,11)
          EvidenziaRigo=true
        else
          messagebox ActualDate.SQLDate + " < " + d2.SQLDate + " and " + listboxingressi.CellTextAt(row,11)
          EvidenziaRigo=False
        end if
      end if
      
      
      
    end if
  end if
  
  
  
end if




if row Mod 2 = 0 Then
  if EvidenziaRigo=True then
    g.DrawingColor= &cff1100 ' RED
    g.FillRectangle(0, 0, g.Width, g.Height)
  else
    g.DrawingColor= &cf0ffff ' heavenly/celestino
    g.FillRectangle(0, 0, g.Width, g.Height)
  end if
Else
  if EvidenziaRigo=True then
    g.DrawingColor= &cff1100 ' RED
    g.FillRectangle(0, 0, g.Width, g.Height)
  else
    g.DrawingColor= &cFFFFFF  'WHITE
    g.FillRectangle(0, 0, g.Width, g.Height)
  end if
End If

![Immagine|581x90](upload://lRkZTPdW6m06W1Jtoqy6fHEuuA.png)

Paint events really need to be *just* painting/drawing code.

You should relocate where you determine whether the row is colored or not, and only check for your flag indicating color in the Paint event. You can store the EvidenziaRigo Boolean as a RowTag or CellTag and then check for that.

That said, the code that sets EvidenziaRigo=true is only checked for columns 6 and 9, so you’ll only get coloring for columns 6 and 9. You need to FillRectangle in every cell on a row to color the whole row. Another great reason EvidenziaRigo should be a Row or CellTag.

1 Like

you have to store this data for EvidenziaRigo first, then paint the list.
you could make a method for it, store the value then refresh/invalidate the list that paint event comes.
because you compare with ActualDate you can use a timer as trigger for calculate the color.

Ok it was as I understood, the PaintCellBackGround reads every cell for the entire staff… Thanks for the clarification.

To clarify, it fires for only those cells which are currently visible and need to be repainted. So if you have a large table and only a portion of it is visible, then only those cells will get the event called.