I am new to Gambas, coming from Xojo, and trying to come to terms with making a new class based on a TableView. I am missing something, probably quite simple. I've created a class called SearchBox. I have put in the line Inherits TableView. I've added a SearchBox to the main form and it looks like a TableView and shows data okay. I would like my SearchBox to respond to the KeyPress event but I have had no luck so far. I have looked in examples from the Software Farm but haven't found anything (that I understand). I have the following Sub in the SearchBox class code, and it was working fine before I moved it into a class. I am guessing Me_KeyPress is not the right name for the handler. I'd be grateful for some help.

Hi GB,
Right click on the form with the table view and 'mouse over' the 'Event' selection in the menu list.
This will show you all the events that are accessible for the form ( works the same with any control as well).
If any events have code already written, they will have a tick mark against them.

Select 'KeyPress' and it should drop you to the editor with the correct syntax to trap key events.

Thanks Quin. I think you are saying that the KeyPress handler has to be in the form, and duplicated for every instance of the class SearchBox that I have. Which is what TableViews do, and I should have thought of that. I can simplify things by calling the code I typed in my first post "CheckKey" and put that in the SearchBox class, and then the form would have short handlers like

Public Sub SearchBox1_Keypress()
CheckKey
End
Public Sub SearchBox2_KeyPress()
CheckKey
End

That worked fine. I dragged an instance of SearchBox from the toolbox of classes onto the form. (I found I had to have the word EXPORT in at the start of the class and run the program for it to appear in the toolbox.)

However, when I tried to instantiate the SearchBox in code using

Public sb1 As New SearchBox(FMain)

the sb1_Keypress and sb1_Click and sb1_Save handlers in the form's code don't do anything.

So there is still something I am missing. What else do I need to do when I instantiate a class in code? Thanks.

From what I'm reading it seems like you are creating a 'new' component rather than just instantiating a user created class.
Read some detailed information about how to do that here: http://gambaswiki.org/wiki/dev/gambas

From your initial post, I had thought that you were just creating a helper/toolbox class for a standard TableView as this would be the simplest way. My Bad.

Something to note; You can pass a control ByRef to a class subroutine as a parameter and then act on it as desired.
ie: Set the alignment of the GridView columns ( same as a TableView but not editable )
If the gridview has 3 columns that you want set as: center, center, right, you would pass these parameters.

Thanks, Quin. I shall read up on components, though I don't think I am ambitious enough to make any of those. I am not quite ready to add to Gambas itself. I am satisfied if I can add to a program. I understand your code about passing a class ByRef to a sub.

Your earlier advice answered my earlier question perfectly. Events have to have handlers in the form. It is no use having the handler in the class. So obvious. The class holds various subs that you can call upon, but the calling has to be done from event handlers in the form.

I don't expect to ever really need to create an instance of a class from within code. Dragging one onto the form at design time is all I shall use.

I wrote a version of a game once—the commercial version was called "Concentration"—where you turn over cards and if you find a match the pair was removed, trying to remember where matching cards were. A bigger board size showed more "cards", and (this is in Xojo) I made as many instances of the card class as the user asked for. But gridviews show pictures in cells, so it is much easier to have one gridview with 6x10 rows and columns than 6x10 instances of a card class. So instantiating a new class derived from a TableView using code is just for academic interest only. Thanks again. Shall read up on components.

I've been going at Gambas heavily for about four months now. My initial assessment is that Component development is unnecessarily cumbersome. Let's leave it at that for now.

If I need something only C can do, I have found writing a shared library to be much easier, and much more productive. If I need something on the forms, the controls that exist have been adequate for all my needs.

I recommend you load and run, then read, the programs I posted in "Programming is supposed to be fun"