Listbox: I can edit a non existant cell

I reported that years ago (and I forgot the result).

I was unable to connect to the internet 'till minutes ago and so, I was fooling around and falled into that.

I created a new empty project (2015r1),
add a Listbox (20,20, 560,360),
set the ColumnWidths to 100

and add two Events with code:

[code]Sub DoubleClick()
Dim row,column As Integer

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)

Me.CellType(Row,Column) = ListBox.TypeEditable
Me.EditCell(Row,Column)

Me.CellType(Row,Column) = ListBox.TypeNormal
End Sub[/code]

Sub Open() Me.AddRow "Cell 0, Row 0" End Sub

Run,
Double click in the non existant second column, row 0 area and get the Editable TextArea.

Must I report a bug ?

PS: there is no other code nor change from the default Listbox.

Edit:
I knew I forgot something, but what ?
Also tested with Xojo 2019r1 and same result: I am able to edit a non existant Cell, type data that are lost when I exit the non existant cell. :wink:

Sorry I deleted my last post, I wanted to edit it.

Now I see the problem.

Edit: I guess you can code something simple to get the behavior you want, either change column value when 1 to 0, or do not execute the celltype change if column = 1.

I shared a demonstration.

My running project have a certain number of colums, have an horizontal scrollbar, etc. and this is there that I saw the trouble.

I build the demonstration project to just do that: inform everybody about this.

Now all readers know about it and how to replicate. I’ve made my job.

BTW: how do you exclude a (double) click on an inexistant column ? :wink:

If Column = infinity Then Return End If

@Emile Schwarz — [quote]Now all readers know about it and how to replicate. I’ve made my job.[/quote]

Well it would be nice of you to submit a bug report so there is a chance Xojo will fix this. You have already done the hardest part, which is creating an example project to demonstrate the bug.

The workaround is actually quite simple here (in DoubleClick event):

[code]Dim row,column As Integer

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)

//WORKAROUND
if column>me.ColumnCount - 1 then
beep
return
end if

Me.CellType(Row,Column) = ListBox.TypeEditable
Me.EditCell(Row,Column)

Me.CellType(Row,Column) = ListBox.TypeNormal
[/code]

the cell exists - it just has no data in it (the string in it is “”)
adding a row adds ALL cells - some may just be empty

@Norman Palardy — But in this case, there is only one column which does not take the whole width of the ListBox, yet no method raises an exception for accessing a second column which does not exist.

The column returned by CellClick should NOT exceed the ColumnCount-1
but per a test I just ran… it sure as heck does

I made a listbox that was 200 pixel wide, with a single column at 100px wide, but clicking in that “dead area” returned Column 1

clicking beyond the ROW works fine… but active column seems to be (IF column<=ColumnCount) but should be (IF column<ColumnCount)

this isnt new - pretty sure you could go back in historical releases & get the same effect
the bug has already been reported
<https://xojo.com/issue/49612>

Oh no :frowning: Emile will be devastated to discover he already reported this bug 1.5 years ago and he doesn’t remember. Alzheimer?

(I am kidding Emile! I wouldn’t do that to another Strasbourgeois)

No problem Stphane (and yes, I have some memory troubles I try to compensate with far more work, but sometimes)

I forgot about the bug report, but I recall having already talked in this forum about it.

Now, the 1 column trick (and 100 pixels *) are only for the demo: this trouble appears to me in a far larger project with an horizontal scrollbar, etc.

In that project, the 9 default column widths are 100 pixels wide each.

@Emile Schwarz — Well I hope my workaround will work on your larger project

[quote=433587:@Emile Schwarz]BTW: how do you exclude a (double) click on an inexistant column ? :wink:
[/quote]
I think this will work:

[code]if column < me.ColumnCount Then
Me.CellType(Row,Column) = ListBox.TypeEditable
Me.EditCell(Row,Column)

Me.CellType(Row,Column) = ListBox.TypeNormal
End
[/code]

Tested with 4 column sample (from Robin, case 49612), changed:

Function CellClick(row as Integer, column as Integer, x as Integer, y as Integer) Handles CellClick as Boolean // Set the current Cell to Editable Me.EditCell(row,column) End Function
to

Function CellClick(row as Integer, column as Integer, x as Integer, y as Integer) Handles CellClick as Boolean // Set the current Cell to Editable if column < me.ColumnCount Then Me.EditCell(row,column) End End Function