Press Return to validate an Open Dialog is passed to a ListBox

The code below is in a ListBox’s KeyUp:

[code]If Key = Chr(4) Or Key = Chr(13) Then
// Store the actual Row #
EditionRow = Me.ListIndex

// Set this Row as Editable…
Me.EditCell(EditionRow,0) // Place the Cursor in the Column 0 [temp]
End If[/code]

The problem lies at Open’s time after I pressed the Return key (instead of a click in the Open button) in the Open Dialog: the Return key is passed to the ListBox.

To avoid that, I have to click in the Open button (of the Open Dialog).

I nearly forgot:
I got a beep each time I press the Return key to edit a ListBox Cell.

I think, you should move your code from the KeyUp to the KeyDown event (and return True there for the cases you wish to handle, so the framework stops handling the event itself).

Hi Eli,

thank you for your answers.

I tried that,
get the same trouble,
and it is more complicated to work with…

a too fast typed Return True (at the bottom of the event) disallowed me to use the arrow keys ;-:).

So I Cut / Paste back the code to KeyUp (I do that many times until I no more feel insecure !).

What about the Beep ?

The beep is because the framework doesn’t know what to do with the keystroke. You should actually almost never need to use KeyUp. KeyDown is the correct place to handle a keystroke which the Xojo framework shouldn’t handle.

If you have a trouble in KeyDown with too-fast typing I’m almost sure it’s your coding which is wrong. I’ve never had troubles differentiating keys in KeyDown. Maybe you can show us your code?

Code in KeyDown (or KeyUp, I swapped it many times):

[code]If Key = Chr(4) Or Key = Chr(13) Then
// Store the actual Row # (future use)
EditionRow = Me.ListIndex

// Set this Row as Editable…
Me.EditCell(EditionRow,0)
End If[/code]

The bug appears when I import a text file and I press the Return key to select the file from the open dialog.

No Beep, no selectable Cell if I click in that button.

So, I do not understand from where that beep can comes.

At last, the Return key must have been “blocked” before the text is loaded in the listbox, but it is not the case.

I will try that project on Windows this afternoon…

You have to return True if you handle an event:

[code]If Key = Chr(4) Or Key = Chr(13) Then
// Store the actual Row # (future use)
EditionRow = Me.ListIndex

// Set this Row as Editable…
Me.EditCell(EditionRow,0)
Return True // <-------
End If[/code]

[quote=62659:@Emile Schwarz]The code below is in a ListBox’s KeyUp:

[code]If Key = Chr(4) Or Key = Chr(13) Then
// Store the actual Row #
EditionRow = Me.ListIndex

// Set this Row as Editable…
Me.EditCell(EditionRow,0) // Place the Cursor in the Column 0 [temp]
End If[/code]

The problem lies at Open’s time after I pressed the Return key (instead of a click in the Open button) in the Open Dialog: the Return key is passed to the ListBox.

To avoid that, I have to click in the Open button (of the Open Dialog).

I nearly forgot:
I got a beep each time I press the Return key to edit a ListBox Cell.[/quote]
Don’t forget to return true or false when you handle the key
Otherwise it gets passed along

Hi Norman:

thank you for your kind answer. Now I understand what Eli wrote above.

What about my next if / end if block that test the Tab key ?
Must I include it inside the Enter / Return if block ?

What about stopping the Return kep pass along IN THE OPEN DIALOG (that is where the trouble comes, I think).

Note: I was not able to replicate this in a brand new project I wrote yesterday afternoon.

I shared the generated application that have this trouble from here (1.25MB) (Import the provided text file and enjoy the demonstration / the nice ListBox.
I do not implemented “Delete Row” from the Edit Menu because I do not understand how to add the shortcut. I just change the Row contents instead.
This is a simple answer to fit a need I had lately: build a list of data that comes from many magazines on one subject. I started it with TextEdit, but I had troubles after 50 lines or so. Now, with that application, it is more easy to do. And the Red text allowed me to search missing data (or display story not printed in French by that company).

Read the conversation named: ListBox New Feature for more info.

Hi Eli,

I do not spend time to understand why, but in the project I build from scratch, yesterday afternoon, not using code from this one, I placed the code in KeyDown and it plainly does not works. So, I Cut / Paste it in KeyUp and everything worked .

Yes, I read the docs entry for KeyUp.

On the other way, I always think that putting code in MouseUp leaves the user a chance to change its mind and not fire the code there (yes, Mouse, not Key; the when I want to put code somewhere, I think twice before it’s allright).

I never used KeyUp in any of my projects with the exception - in subclasses of RectControls - to reset internal variables. Especially: with KeyUp you can not prevent the framework to process the keystroke, hence you beep. Really: you are doing something wrong, if you can’t get it to work with the code in KeyDown.