SearchField.Pressed help

If you would like to take a look at the project you can download it here.

I can’t seem to get the link working so you can paste this in your browser:

http://www.jlcoones.com\downloads\PrehistoricLife_Test.zip

It’s been told in other threads… but it is a bad idea calling MessageBox from a control event handler. What does it happens if you do other kind of task in the SearchField control?

You can find an Example project using a database in combination with the SearchField under Example Projects > Sample Applications > Desktop > EEDesktop

As proposed by @Anthony_G_Cyphers , probably you’ll want to call a “common” method from the SearchField and the PushButton Pressed event handlers.

@Javier_Menendez
Using the Pressed event in the SearchField is supposed to recognize the Enter Key when pressed. I could not get it to work so I am now trying to use a TextField with a KeyDown event. I used the MessageBox just for testing.

What I find strange is that I can use:

If Keyboard.AsyncKeyDown(&h0D) Then
//searchBtn.Press
//End If

That works for any key on the keyboard except the Enter Key.

I tried using this:

If Key = Chr(13) Then
searchBtn.Press
End If

It does not work for the Enter Key but if I change the ASCII code to any other key on the keyboard, it works. ???

Take the ASCII code for Enter ?

John, you have 3 default buttons on your application: Previous, Next and Exit.
The Tab Order puts Exit before the other 2.
When you press enter/return on your application the code in the Exit button is executed that is why it returns to the IDE because you have “Quit” there, so the application is not crashing but quitting.

@AlbertoD

I have the TextField and the searchBtn at the top right of the screen and I have set the focus to the TextField. I don’t see the searchBtn listed in the TAB order.

The other thing that I don’t understand is in the KeyDown event for the TextField I can use any key on the keyboard and searchBtn.Press works except for the Enter Key?

image
image
These 3 buttons are set as Default and they are trying to “capture” the Enter key
image

I think if you turn Default to Off on all 3, then you will be able to use the Enter key with your TextField. I haven’t tried that.

Edit: PushButton (deprecated) — Xojo documentation

If True, the default button indicator is added to the button and the Return and Enter keys are mapped to the button.

@AlbertoD
Thank you so much AlbertoD. I turned off the defaults on all 3 buttons and the KeyDown event now works using:

If Key = Chr(13) Or Key = Chr(4) Then
searchBtn.Press
End If

Thanks again. :smile:

I suppose that the .sqlite file is not complete.

@Emile_Schwarz
The file is as complete as it will be for a while. There have been some new discoveries over the past 2 or 3 years and I have not had a chance to update it with the new information. Did you try the app?

I get an eye on it, then saw Alberto’s answer, find it strange and saw default buttons are not visually different in the IDE… and that is error prone.

Then, hours later, I recall seeing the .sqlite file and open it too look at it.

No T-Rex (T, yes, but not Royal :wink: )
No Pterodactyl.
But Steggy was there…

It was late, so these are the two I recall…

I love the idea.

BTW: the source project. A simple advice (and you used it, but not in these TextFields):
change the TextField(s) names from TextField1…n to TF_DataBase_Column_Name to avoid eventual trouble in reading / writing the dataBase. With a simple look, you will be able to watch an eventual error.

@Emile_Schwarz
There is a Tyrannosaurus in there. There is no Pterodactyl but there is 3 or 4 very similar species in there. It took me a long time to get the 115 records in there and I may add some more later. If I had life to live over again I might be a paleontologists. :slightly_smiling_face:

BTW: Is there a way to tell if a record has been found or not found? I noticed that if a dino is not found, it displays a blank record. If a record is not found, I’d like it to stay on the previous record and maybe pop up a MessageBox(“Record Not Found!”)

Cheers.

@Emile_Schwarz

Blockquote – A simple advice (and you used it, but not in these TextFields):
change the TextField(s) names from TextField1…n to TF_DataBase_Column_Name

I tried to change the names of the TextFields but I get a dialog box saying “Every control array must have the same superclass type.” It’s a TextField so I don’t know where it is getting the “array” from.-

Are you sure you didn’t create a control set by mistake? Are you changing the Name or the Super of the control?

@TimStreater
I didn’t create a control set. When I was laying out the UI I simply dragged a TextField onto the screen. I have several other TextFields in the UI as well and they all get the same dialog box. I am trying to change it from “TextField1” to “name”. I even tried deleting TextField1 and then adding a new TextField but got the same dialog box when I changed the name.

Can you show a screenshot of the dialog box?

@TimStreater

I think you can’t have a Label and a TextField both named “name”. I use l_name, tf_name

I have changed TextField1 to TF_Name without trouble.

And Alberto is correct: a Control name have to be unique, s use L_Name and TF_Name, etc.