ListBox: I am able to edit a non-existing Cell !

Hi,

It goes like that either with a Tab (after a Return to enter in Row Edit Mode of the main window’s ListBox) AND by a click in a non existant Cell.

My Tab edit code may be wrong (the 0 - 1 based… trouble), but been able to edit a Cell in an inexistant Column (cell…) by a double click…

Watch the image below:

For those who want to know, here is the “Edit the double clicked Cell” code directly (nearly) from the Language Reference:

[code] //
// Allows to Edit the Double-Clicked Cell
//
// Code from the Language Reference
//
Dim Row As Integer
Dim Column As Integer

// Get the Reference of the double clicked Row / Column (as numbers)
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)

// Copy these values to my Properties *
EditionCell = Column
EditionRow = Row

// Set the Cell Editable
Me.CellType(Row,Column) = ListBox.TypeEditable

// Allow to edit the Cell
Me.EditCell(Row,Column)[/code]

  • There is reasons to set these variables, in another part of the code (ListBox.KeyUp).

What is the ColumnCount of the listbox?

I do not know, but as you can see the “last column” have nothing in it nor in the Header.

BTW: I forgot to mention that the text placed in that out of bounds column is lost when another row is selected (and this does not happens on other columns).

Also, I’ve set fixed values to each columns and that “last Column” is resized if I resize the window; the horizontal scrollbar appears only when the window bound is in MY last Column (teh real last column).

At last, it is very easy to re-create the trouble:

add a ListBox to the window, set the column count to 7 (any other value is fine, I found it with other data (less columns), fill the column widths with fixed (not variable, no *) amount of pixels run.

I really feel this is a bug. But it is too incredible to be true.

Just tried it, and this doesn’t happen to me. That’s my code in the listbox’s open event:

// In the For i As Integer = 0 To Me.ColumnCount - 1 Me.ColumnType(i) = Listbox.TypeEditable Me.Column(i).WidthExpression = "100" Next
The area right of the last column is not editable.

I do not use that kind of code.

I set the selected Row, Column 0 as editable if a Return (or Enter) key have been pressed,
I set as Editable the next Cell if a Tab key was pressed.

I also used the above code for DoubleClick. Remove :

EditionCell = Column EditionRow = Row

to run it.

Oh, do not forget to add data to the ListBox AND to anlarge the window to display a unused column at window’s right (past the used Columns).

I will make more testing this afternoon and come back here tomorrow.

Good Sunday to all readers.

Of course I added data to the listbox and enlarged the window (“The area right of the last column is not editable”). I still suspect that you have one column too much.

I get the phantom cell with this…

place a Listbox, name it lb and add open code

[code]Sub Open()
me.ColumnCount = 2
me.ColumnWidths = “100,100”
me.HasHeading = true

for i As integer = 0 to 9
me.AddRow Str(i)
next
End Sub[/code]

then add a pushbutton to manually edit

Sub Action() lb.EditCell(1, 2) //3rd column is editable, but not saved //lb.EditCell(1, 3) //4th column raises error End Sub

Columns are zero-based, so the following code:

lb.EditCell(1, 2)

turns on editing for column 3!

but there’s only 2 columns

Yes, column 0 and column 1.

I found the culprit. Read the whole story with project and app in “ListBox New Feature”.

The problem lies when setting LB.Heading. Valid LB.Heading.
(it may be LB.Heading(-1) = “String with Tab separators” I do not know / not tested / I just think at that)

You can then see a faked column (you CANNOT press its Header) that fills the space between the last valid column (you can press its Header). If you do not fills the Header (like above), you will get a true empty space instead of this “fake Column”.

Download the project and see by yourself. The project example have been created from scratch and use “new code”: no code nor atom from the “main project” have been used in that example. I do not even load the original project to copy code / element or refresh my memory on how I wrote it. I only took code from the docs (Double Click) and wrote the rest of the code (so few code).

The other link holds the application who displayd the Return pass thru, displays what I’ve done for the Edit Cells, Insert Row, set Row text to Red if Cell(Row,0) is empty, etc.

I think we’re misreading each other (or its just me:)

The code I posted is correct as far as 0/1 basedness; it shows a 2 column Listbox have an editcell appear in the nonexistent 3rd column.

In another thread you mentioned this is a ‘free space’ column which needs to be there for CellBackgroundPaint to fire. I can see that, that the internals tack on a column to homogenize handling free-space, still I consider being able to editcell there a bug. A pretty minor bug though, only present when the coder makes a mistake.