ListBox crash after pressing Return (in Cell Edit Mode)

Hi,

I add a MenuItem that Toogle the Cell Edit Mode (On / Off).

In a ListBox, when I set the Edit Mode On, I am able to Edit all Cell(s) of a Row and even one I do not know from where it comes.

After two or three times I click on that “non existant” Cell (Column) *, I at last decided to place some text there, then press Return and crashed on the Debugger with the OutOfBounds exception error. This seems normal to me (but not been able to edit a non existant Cell).

  • This is not related to the “white column” bug I already reported and who have a bug report.

Image 1. The Extra Column in Edit Mode

(yes, the white part on the right of the ListBox is still here, but not related to this discussion AFAIK)

The TextField at the window bottom mirrors the selected line contents.

Image 2. The Debugger AFTER pressing in the Return Key

I was awaiting that to be fired before the Return key press, if the Cell is out of bounds…
But a bug is a bug and do follows only its onw rules.

That message says ‘out of bounds exception’… thats not a crash…

You should have wrapped this code in something to test which row and column you are on before trying to amend the cell.

I expect that the value of column at this point is the last column.
Trying to set the cell in column+1 to be editable causes the problem.

It isn’t what most people would call a crash: at the very simplest you could wrap this up with a try…catch and ignore the exception…

OK Jeff, but why can I edit a non existant Cell ?

I checked carefully how I build the ListBox to be sure there is nothing there from me.

In fact, I put the AddRow code in the Open Event. That is why I know there is no Cell there.

Can you?
Isn’t the message above saying precisely that you can’t edit the cell because it doesn’t exist?

OK. Time to explain a bit:

if when I click in a cell, I can type text, for me, that means a Cell exists.

If I click in Row 1 (or any other Row except Row 0), I will get nothing (and I will check this assertion later).

So, if I am not wrong,I cannot type text in a non existing Row, Cell.

A user (eventually a Newbie) will never understand that concept.

Thanks for trying to help.

The invisible column is an extra column thingy added behind the scenes to manage leftover column space. The problem is this extra column is not completely inaccessible, and doesn’t update properly when resizing columns.

This example creates a 2 column listbox, thin columns so there’s plenty of empty space on the right. With 2 columns the only EditCells you should be able to do on the first row are me.EditCell(0, 0) and me.EditCell(0, 1). But there is a 3rd ‘invisible’ column to manage that extra space and me.EditCell(0, 2) brings up the ActiveCell there. You don’t get an OutOfBounds until me.EditCell(0, 3).

Also, there’s no OOB in setting the text of this invisible cell, me.Cell(0, 2) = “foo”. foo won’t be drawn in the listbox but does appear when me.EditCell(0,2).

Then if you resize the columns thinner you’ll see the painted red regions width isn’t updated, leaving an unpaintable white region. Resizing the Listbox will update the extra column.

So the bug is that me.EditCell(0, 2) doesn’t trigger an OOB, and that the width isn’t updated during column resizing.

Actually, looking at the docs now after the fact I don’t see mention of OOB values so it’s sorta undefined what they should be. Maybe the OOB behavior is intentional.

//Listbox1, locked on all sides

Sub Open()

  me.ColumnCount = 2
  me.ColumnWidths = "100,100"
  me.ColumnsResizable = true
  me.HasHeading = true
  
  me.AddRow "a", "b", "inv"
  me.AddRow "c", "d", "isi"
  me.AddRow "e", "f", "ble", "xx" 
  
End Sub


Function CellBackgroundPaint(g As Graphics, row As Integer, column As Integer) As Boolean

  if row < me.ListCount then    //real rows...
    if column < me.ColumnCount then
      g.ForeColor = &c80FF80     //green for real cells
    else
      g.ForeColor = &cFF8080     //red for 'invisible' cells
    end
  else
    if column < me.ColumnCount then
      g.ForeColor = &c8080FF     //blue
    else
      g.ForeColor = &c808080     //grey
    end
  end
  g.FillRect(0, 0, g.Width, g.Height)
  
  g.ForeColor = &c000000       //border
  g.DrawRect 0, 0, g.Width, g.Height

End Function


Function CellClick(row as Integer, column as Integer, x as Integer, y as Integer) As Boolean
  me.EditCell(row, column)
End Function


Function CellKeyDown(row as Integer, column as Integer, key as String) As Boolean
  if key = Chr(13) then
    me.EditCell(row, column + 1)
    return true
  else
    return false
  end
End Function

Jeff, did you even read Emile’s first post completely? Your comments are besides the point

Also, it looks like this is a Web related issue, isn’t it? Shouldn’t this post be moved to the proper subforum, then? Or can you reproduce this with a Cocoa build as well?

No. This is desktop alright. Emile has been entertaining this extra column thing for quite a while.

Seems he has trouble setting up columns width, and somehow loves his pet bug…

When I look at Will’s example , 2 lines are enough to prevent the OOB.

CellClick

if column < me.ColumnCount then
me.EditCell(row, column)
end if

CellKeyDown

if key = Chr(13) then
if column < me.ColumnCount-1 then
me.EditCell(row, column + 1)
end if
return true
else
return false
end

Got it.
That does look wrong.

Sigh.
The post title clearly talks about a ‘crash’.
The ‘crash’ is just an exception, and is avoidable using normal error trapping.

If an non-existent cell can be placed in edit mode by the control itself, thats a Xojo bug, and should be logged via feedback.
If me.editcell(row, column+1) causes an OOB, thats trappable.

[quote=186088:@Michel Bujardet]No. This is desktop alright. Emile has been entertaining this extra column thing for quite a while.

Seems he has trouble setting up columns width, and somehow loves his pet bug…[/quote]
Michel:

  1. Read carefully my post,

  2. No pet dog here. This is different beast: not a user interface refresh thingie; you can see it if you watch carefully the first screen shot:
    at the right of the ListBox there is a small Cell in Edit mode, then (and then only) a white part (the so called pet dog).

As I wrote earlier: I added by code two lines in the ListBox Open event: one to add the headers, one to add the first Row.

I do not know how I can do fancy things in two simples Me.AddRow lines…

I will explorate the provided code later, thanks.

Will: I just read your description and this looks like a bug (to me).

NOTA: I just clicked by pure hazard there… and discovers that and share it here. After that I thinl at how Joe / Jane Newbie will think when falling into that.

Xojo ?