PaintCellBackground issue

Hello,
I know it may be a silly issue: I have a 3 column ListBox, Column 1 should be painted yellow anytime it holds the word “Juniores”. Here’s the code:
"Var jun As Integer
if row mod 2 = 0 Then
g.ForeColor = &cf3f6fA
g.FillRect(0, 0, g.Width, g.Height)
end if

For i as integer = 0 to Me.LastRowIndex
if Me.CelltextAt(i, 1) = “Juniores” then
jun = i
end If
If row = jun and Column = 1 Then
g.DrawingColor = &cFFFF66 //Yellow
g.FillRectangle(0, 0, g.Width, g.Height)
End If
Next"

I knwo it is not the best coding you have seen but it works except that it paints yellow Row 0, column 1 even if it does not meet the criteria.
I have the same issue in other ListBoxes as well. Only that very first cell (see picture).
I tried different approaches but to no avail.
Any body can help?
Also, if you have a better or nicer coding for the same issue I’d appreciate the suggestion.
Thank you

Change that to

Var jun As Integer = -1

for example.

Because at first for jun = 0 and Column = 1, so that cell will always be yellow.

Do you have that code in PaintCellBackground? If yes, you don’t need to check all the cells all the time.

Edit: I have seen code like this for PaintCellBackground

If  row > Me.LastRowIndex Then Return True
If Me.CellTextAt(row, 1) = "Juniores" Then
  g.DrawingColor = &cFFFF66 //Yellow
  g.FillRectangle(0, 0, g.Width, g.Height)
End If

It works as far as the first cell not being painted but, on the other hand, this code paints the whole row. I’d like to have the single cell painted

Are you talking about this change in your code?

Var jun As Integer = -1

or using this code?

If  row > Me.LastRowIndex Then Return True
If Me.CellTextAt(row, 1) = "Juniores" Then
  g.DrawingColor = &cFFFF66 //Yellow
  g.FillRectangle(0, 0, g.Width, g.Height)
End If

if the latter, then you can add a restriction before the code like:

if column <> 1 then Return True //do not paint background other than column 1

I will test and report back.

Edit: yes the original 5 lines code I posted paint each cell for a row where ‘Juniores’ appear on column 1. Adding the restriction to only paint column 1 makes the code work as you expected.

Adding the final code with comments, that may help you work other cases:

//do not try to paint rows outside our content
If row > Me.LastRowIndex Then Return True
//do not paint background other than column 1, remove if you want to paint the whole row
If column <> 1 Then Return True
//check (row, column=1) for 'Juniores'
If Me.CellTextAt(row, 1) = "Juniores" Then
  g.DrawingColor = &cFFFF66 //Yellow
  g.FillRectangle(0, 0, g.Width, g.Height) //paint background for the cell
End If

It works.
Thanks a lot

Happy to help.
You can check my edit (code with comments) that may help you adapt the code to other needs.