Listbox CellBackGround Event Causes Windows Build to Crash

I have a listbox causing a Exception of Class OutofBoundsException Not Handled Error on the Windows build. The listbox is located on a pagepanel tab which is not shown when the app opens; however, as soon as the tab is shown the listbox is drawn causing this error. The Mac build works perfectly. I am testing in XP Pro.

The listbox opens with a default color of white in the column 0 and the other columns are light gray. When the user clicks a cell in the first column they are able to select a color and that color is then drawn in column 0 and the color’s hex value is shown in column 1.

I believe this line of code is causing the problem as if its taken out the app does not crash:

G.ForeColor = Me.CellTag(Row, 0)

Open Event:

Dim DoIt as Integer
  
  For DoIt = 1 to 24
    Me.AddRow ""
    Me.CellTag(Me.LastIndex, 0) = &CFFFFFF
    Me.Cell(Me.LastIndex, 1) = "FFFFFF"
    Me.Cell(Me.LastIndex, 2) = "CC"
    Me.Cell(Me.LastIndex, 4) = "-"
  Next
  
  Me.ColumnType(1) = 3
  Me.ColumnType(3) = 3
  Me.ColumnAlignment(1) = 2
  Me.ColumnAlignment(2) = 2

CellBackgroundPaint Event:

  G.ForeColor = &cF0F0F0
  G.FillRect(0, 0, G.Width, G.Height)
  
  If Column = 0 and  Me.ListCount <> 0 then
    G.ForeColor = Me.CellTag(Row, 0)
    G.FillRect (0, 0, 30, G.Height)
    Return True
  End If

CellClick Event:

  Dim C as Color
  Dim B as Boolean
  
  Row = Me.RowFromXY(System.MouseX - Me.Left - Self.Left, System.MouseY - Me.Top - Self.Top)
  Column = Me.ColumnFromXY(System.MouseX - Me.Left - Self.Left, System.MouseY - Me.Top - Self.Top)
  
  Select Case Column
    
  Case 0
    
    If Me.CellTag(Row, 0) = Nil then
      C = &cFFFFFF
    Else
      C = Me.CellTag(Row, 0)
    End If
    
    B = SelectColor(C, "Select Color")
    
    If B then
      Me.CellTag(Row, 0) = C
      Me.Cell(Row, 1) = Replace(Str(C), "&h", "")
    End If
    
  Case 2
    
    Dim Clip as New Clipboard
    Clip.Text = Me.Cell(Row, 1)
    Clip.Close
    
  Case 4
    
    C = &cFFFFFF
    Me.CellTag(Row, 0) = C
    Me.Cell(Row, 1) = Replace(Str(C), "&h", "")
    Me.Cell(Row, 3) = ""
    
  End Select

How do you set Row ?

[quote=146834:@art ouette] G.ForeColor = &cF0F0F0
G.FillRect(0, 0, G.Width, G.Height)

If Column = 0 and Me.ListCount <> 0 then
G.ForeColor = Me.CellTag(Row, 0)
G.FillRect (0, 0, 30, G.Height)
Return True
End If[/quote]

Check that ROW >= 0 since this gets called for all VISIBLE rows not just ones with data

I tried this but am getting the same error:

  G.ForeColor = &cF0F0F0
  G.FillRect(0, 0, G.Width, G.Height)
  
  If Column = 0 and Row >= 0 and Me.ListCount <> 0 then
    G.ForeColor = Me.CellTag(Row, 0)
    G.FillRect (0, 0, 30, G.Height)
    Return True
  End If

[quote=146834:@art ouette]I believe this line of code is causing the problem as if its taken out the app does not crash:

G.ForeColor = Me.CellTag(Row, 0)
[/quote]

If you are positive that is the line where the error occurs, it must be one of the terms of the thing. Since you verified Row, I suspect it may be CellTag. I would try something like

G.ForeColor = &cDDDDDD

If the error goes away it means whatever was in CellTag was an invalid or nil value.

I think Norman meant, check that Row < ListCount. CellBackgroundPaint is called for every row of the listbox, even ones that have no data in them. If Row is >= ListCount, accessing CellTag(Row) will be out of bounds.

= 0 & < listcount
right tim

Right, if you’re accessing RowTag (and a few others) you need to check both ends.

That did the trick - thank you!

This Works for the CellBackgroundPaint Event:

  G.ForeColor = &cF0F0F0
  G.FillRect(0, 0, G.Width, G.Height)
  
  If Column = 0 and Row >= 0 and Row < Me.ListCount and Me.ListCount <> 0 then
    G.ForeColor = Me.CellTag(Row, 0)
    G.FillRect (0, 0, 30, G.Height)
    Return True
  End If

If you work out the logic, and Me.ListCount <> 0 is not necessary, as it is an impossible situation given the other conditions.

In the Mac version I have the App add 24 rows by default as that entirely fills the area of the listbox. On Windows XP the listbox rows and text are smaller so to fill up the remaining area of the listbox Windows has added approximately 5 1/2 blank rows below those I added with code - they are all grayed out and can’t be selected. Any idea why this occurs?

Hi Art

your crashes in Windows might have another cause.
I have had several instances where in the windows built, the call to some (not all) windows resulted in crashes.
I got this when one window call a second one’s opener and then finishes off the calling method ending with self.close
The other instances are when building a file and trying to launch it.

The fix goes back to 2004 when Realbasic had a bug, which was subsequently fixed.
Either call the CloseWindow method or add the code before f.launch

Timer1.Period = 5 ’ No need to wait long.
Timer1.Mode = 1 ’ Only need to trigger Action once.

Because the listbox is larger than the content. Those aren’t blank rows, that’s an empty area where you haven’t added any rows.