Trap KeyPress on Table

marathon332

Member
Licensed User
Longtime User
Hi...

I'm trying to trap a keypress while my table control has the focus on the desktop.

I want to open a new form when a table row is selected and the user presses return or maybe double clicks a cell.

I tried using the door library but I can only trap keys when the form has the focus. The same code won't work for the table at least the way I'm doing it...

Any ideas on how this can be accomplished?

Thanks...
 

mjcoon

Well-Known Member
Licensed User
I'm using the Hardware.dll to trap "hard" keys and this seems to work if controls belonging to the form have the focus.

I don't care which control has focus. But if you do you could use a global flag to set "True" only when the relevant control has focus and test that?

(You aren't telling us much about your running environment!)

Mike.
 

marathon332

Member
Licensed User
Longtime User
Mike:

Thanks for your reply...

I'm working on the desktop so the hardware dll won't work here...

The door.dll is probably the answer but I can't make it work the way I want it to...

I'm open to any possible solution that works with the return key or a double-click on a selected table cell...
 

agraham

Expert
Licensed User
Longtime User
This description and program apply to the desktop only, the device DataGrid on which Table is based is much simpler and implemented differently.

What you want is complicated because as soon as you click on a cell in a Table the cell is selected and a text box is overlaid at that location. As the DataGrid in the Compact Framework is read only the desktop one is made read only but the text box is still overlaid and captures all the events. That is probably why you have no success with the Door library.

Try this program. It is a bit of a fudge in that it uses the Click, not the DoubleClick, event. The first click on a cell selects it and the second fires the event. If you hooked the DoubleClick event you would need to make three clicks.

I don't seem to be able to hook any key events, probably because the text box doesn't see them as the Table is read-only.
 

Attachments

  • TableEvents.sbp
    1.5 KB · Views: 193

marathon332

Member
Licensed User
Longtime User
Thanks Andrew, that did the trick with the double-click and I'm very happy with the solution you provided...

That door library is really useful but very complex especially if you don't understand the differences between Basic4ppc and the .Net controls.

Too bad there wasn't a clear tutorial to fill in some of the blanks but hey... I understand that there's a lot of work involved that takes away from the fun of programming...

Anyway, thanks again and keep up the good work!

--Steve

BTW, is a keytrapping library for the desktop possible at some future date? Might be a good addition for these cases. Just a thought...
 
Last edited:

agraham

Expert
Licensed User
Longtime User
Too bad there wasn't a clear tutorial to fill in some of the blanks but hey
If you mean for the Door library you can't really write a tutorial for it. It is a "doorway" to the Common Language Runtime and it's libraries. How to use it is simple, to understand what to use it on is the trick. I had to Google and poke around in the .NET docs for a couple of hours to understand the DataGrid control and come up with that code fragment. You just can't tutorialise stuff that complex.
BTW, is a keytrapping library for the desktop possible at some future date?
Probably not for the reasons given above. To implement a straightforward "missing" event on a normal control with the Door library only takes three lines of code, and one of them is to New the Event object so I don't see how another library could help.
 

marathon332

Member
Licensed User
Longtime User
I understand what you're saying and really appreciate the effort you put into helping me solve this problem. We're really lucky to have you on this forum. Great job as usual...
 
Top