Getting cell value in CellBackGroundPaint

Hi,

I am trying to get the value of a cellTag in CellBackGroundPaint. However when it gets to

  Dim TrackID as string = me.CellTag(row,1)

It calls the function again and we get into a loop. Can someone please tell me what i am doing wrong here? Thanks
Here is my CellBackGroundPaint function

[code] if row mod 2=0 then
if me.ListIndex<>row then
g.ForeColor=&cECF3FE
g.FillRect 0,0,g.Width,g.Height
end if
end if

Dim TrackID as string = me.CellTag(row,1)
Dim haveTrack as Boolean = false
Dim ImageFile As FolderItem
Dim PlusSign As Picture
Dim x, y As Integer
dim i as integer

'Listened too
If column =1 Then

i = 1
while i < app.ListenTo.count
  dim s as string = app.ListenTo.Item(i).StringValue
  if s = TrackID then
    haveTrack = true
    Exit While
  end if
  i = i+1
Wend 

if haveTrack then
  ImageFile = GetFolderItem(app.FilesPath).child("Images").child("listened.png")
  If ImageFile <> Nil And ImageFile.Exists Then
    PlusSign = Picture.Open(ImageFile)
    If PlusSign <> nil Then
      g.DrawPicture  PlusSign, 2,2
      Return True
    End If
  End If
end if

End If[/code]

[quote=66834:@Chris Mortimer]Hi,

I am trying to get the value of a cellTag in CellBackGroundPaint. However when it gets to

  Dim TrackID as string = me.CellTag(row,1)

This won’t call CellBackGroundPaint
However you should also check if ROW < 0 or > listCount-1 and NOT try to get the cell tag in that case as that cell has no data

Thanks for the reply. I have added

if row >= 0 and row < me.ListCount -1 then around the code and it is better but the problem is now with

app.ListenTo.Count

Can you access global variables from the CellBackGroundPaint function?

[quote=66881:@Chris Mortimer]
Can you access global variables from the CellBackGroundPaint function?[/quote]

Yes

Thanks for the clarification. The problem was that i had not initialised my collection. All working now and much better with your tip Norman. Thanks.