Several ListBox Gotchas (or questions)

Hi all,

I get the following in a 4 hours coding with Xojo session earlier today.

  1. The line below compiles…
LB.ColumnType(ColIdx) = LB.TypeEditable

And when changed to:

LB.ColumnType(ColIdx) = ListBox.TypeEditable

also compiles, but this is the standard way to do that…

That Copy / Paste weirdness !

  1. While debugging the above troubles (Edit Cell), I found a bug (in my code):
LB.ListIndex = LB.ListCount

The above line make the ListBox loose the Focus (and does compiles fine).
Listcount is 1-based, so I added ‘-1’ to the end of the line and… vogue la barque.

  1. In KeyDown event, key is case insensible.

So, using:

If key ="a" Then

is enough. No need to do:

If key ="z" or Key = "Z" Then

Tip: I used those If blocks as shortcuts to navigate to the first and last Rows in a ListBox: a/z is faster than ‘fn+left‘ arrow or ‘fn+right’ arrow.

  1. Conclusion(s)
    In less than one hour, I falled into three well know development traps:

a. Error in an object reference,
b. The eternal problem with 0-based and 1-based,
c. Case sensitive or case insensitive.

And I do not explain how a nervous breakdown will comes near to me (19th).

FWIW.

LBN: The last one for this pre-breakfast session: I loose the top / bottom arrow default use in the ListBox. I had to add code in the ListBox KeyDown event On the other hand, I added a direct jump to the first / last Row when the currently selectedr Row is the first or the last Row… and I press the top or bottom key.

[quote=183698:@Emile Schwarz]Hi all,

I get the following in a 4 hours coding with Xojo session earlier today.

  1. The line below compiles…
LB.ColumnType(ColIdx) = LB.TypeEditable

And when changed to:

LB.ColumnType(ColIdx) = ListBox.TypeEditable

also compiles, but this is the standard way to do that…

That Copy / Paste weirdness !
[/quote]

Don’t see the issue here. It has always worked that way and it’ by design and not a bug, though

LB.ColumnType(ColIdx) = ListBox.TypeEditable

Is better practice.

Never tried that. A case could be made that an exception should be thrown in that case.

[/quote]
3. In KeyDown event, key is case insensible.

So, using:

If key ="a" Then

is enough. No need to do:

If key ="z" or Key = "Z" Then

[/quote]

How is that a “gotcha”? Both forms work and because of short circuit booleans the second does not cost you much. In any case string comparison being case insensitive is well documented.