Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Home / End Keys to select GO TOP / GO BOTTOM 3

Status
Not open for further replies.

David Higgs

Programmer
May 6, 2012
392
GB
I have a Form with a Grid, when the Grid has Focus the Page Up/Page Down Keys work OK. I would like the
Home / End Keys to GO TOP / GO BOTTOM. How would I go about this?

Regards,

David.

Recreational user of VFP.
 
Funny, these keys should work so natively.

Just testing with a browse of Northwind order detail data the HOME and END keys just are about half a tab/backtab. But indeed a grid on a form handles HOME and END keys correctly.

Could it be you already have some ON KEY LABEL and KEypress code in action messing this up?

Bye, Olaf.

 
Olaf said:
Funny, these keys should work so natively.

Thank you for your reply.

I thought it was a bit strange that the Page Up / Page Down worked but not the Home / End.

Olaf said:
Could it be you already have some ON KEY LABEL and KEypress code in action messing this up?

I've just done a quick search and didn't find anything. I seem to recall that I have used "ON KEY LABEL" in my application but it wouldn't have been on the Form which contains the Grid. It may have been in the Main.PRG I will take further look. Would I need to look further afield than the Form containing the Grid?




Regards,

David.

Recreational user of VFP.
 
Yes, any ON KEY LABEL is global. It's therefore not recommended to make use of, unless you really have a global use for it. And even then, you shouldn't override keys or combinations having a native meaning.

Bye, Olaf.
 
I think we would all agree with Olaf about not using ON KEY LABEL (except perhaps in very exceptional circumstances). It was a useful feature in pre-event driven days. But the problem now is that it can easily interrupt some other event, such as a mouse click on a button, and therefore completely mess up your processing.

And you certainly shouldn't override the keys that have some built-in meaning, including PgUp and PgDown - for precisely the reasons you are seeing. And that applies not just to ON KEY LABEL, but also to other methods of trapping keystrokes.

You might like to use VFP's Code References tool to search your entire project for ON KEY.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike Lewis said:
You might like to use VFP's Code References tool to search your entire project for ON KEY.

The only Files (4 off) that "Code References" found are not called from within the Main.PRG they are for Test Purposes only. I removed them from the "Project" just to eliminate them, it made no difference.

Regards,

David.

Recreational user of VFP.
 
I've just been looking a bit more closely at these keys.

By default, Home and End move the insertion point to the start or end of the current cell (unless AllowCellSelection is .F., in which case they have no effect).

It's CTRL+HOME and CTRL+END that go to the very top of bottom of the grid.

If I was you, I'd be inclined to leave it that way. After all, it's the native behaviour, and as we mentioned earlier, it's rarely a good idea to override that.

But if you really want to use Home and End to go the very top or bottom, you can trap those keys in the KeyPress event, and then programmatically GO TOP or GO BOTTOM, and then call the grid's SetFocus (to make the change visible). You would normally do all that in the grid's KeyPress event, but if the grid's AllowCellSelection is .T., you would have to do it for the individual cells.

The codes to trap in the KeyPress are 1 (for Home) and 6 (for End). So your code would look something like this:

Code:
LPARAMETERS nKeyCode, nShiftAltCtrl

IF nKeyCode = 1
  GO TOP
  This.SetFocus
ENDIF
IF nKeyCode = 6
  GO BOTTOM
  This.SetFocus
ENDIF


Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Well, I just had put a base class grid to a base class form and set recordsource to a dbf of the DE and it worked without CTRL.

Bye, Olaf.
 
Mike and Olaf,

Thank you very much for your help, much appreciated.

I tried Mike's suggestion re: CTRL+HOME and CTRL+END and that worked ok. I also entered Mike's code into the Grids "KeyPress" and that worked ok. So, I have to decide now whether to leave the code in "KeyPress" or place a Note on the Form reminding me to use CTRL+HOME and CTRL+END.



Regards,

David.

Recreational user of VFP.
 
Well, I just had put a base class grid to a base class form and set recordsource to a dbf of the DE and it worked without CTRL.

That's odd. I just did exactly the same thing. I found that Home and End (without CTRL) moved the insertion point to the start or end of the cell, and then moved the hightligh to the next or previous cell (always in same row).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Well, as I also already said, I made another experience in a Browse window than with a Grid on a Form. I believe any quirks you report. There will be some reason, but perhaps it's best, in this case, to simply use the Keypress Code.

I added it to my form and it didn't break functionality (It also wouldn't have surprised me double handling of the keys would have broken their function).

So go for it, use Mikes code and users then either can work with these keys because of it or because of the native form/grid behavior working or because if both. And even if this works twice, you still will be at top or bottom.

Bye, Olaf.
 
Mike Lewis said:
I found that Home and End (without CTRL) moved the insertion point to the start or end of the cell, and then moved the highlight to the next or previous cell (always in same row).

That's exactly what I'm finding when I set AllowCellSelection = .T. although I normally have it set to .F.

So it looks like the "Keypress" option is the way to go.




Regards,

David.

Recreational user of VFP.
 
David,

If you have a grid with more rows than visible on your form:
PgUp moves to the first visible row of your grid
Ctrl+Home moves to the first row of your grid
PgDn moves to the last visible row of your grid
Ctrl+End moves to the last row of your grid.
It seems to me this behavior is Windows like, (I have inserted in MSWord a table and the keys function 100% accordingly like in VFP) I would therefor strongly advise you not to change that behavior, maybe you would like to have it this way but others, MSWord or MSExcel experienced users would prefer to have Windows behavior.

Just my opinion: don't change Windows behavior

Regards,

Koen
 
Koen Piller said:
It seems to me this behavior is Windows like, (I have inserted in MSWord a table and the keys function 100% accordingly like in VFP) I would therefor strongly advise you not to change that behavior, maybe you would like to have it this way but others, MSWord or MSExcel experienced users would prefer to have Windows behavior.

Just my opinion: don't change Windows behavior

Hello Koen,

Thank you for your input, much appreciated.

All my VFP Applications are for my own recreational use and as my Program is still in (continual) Development it maybe wise for me to adopt the Windows behaviour before Home / End become a habit.

Regards,

David.

Recreational user of VFP.
 
I wouldn't say this is normal Windows behavior, as any other application with scrollable window reacts to HOME and END without CTRL, too.

If you do it all on your own for yourself, it's freeing you of the goal to make it a consistent user experience, which in my case works with HOME/END both with and without CTRL in a VFP grid, too.
I seem to be alone with that experience, so there may be something different with my VFP or Windows. I'm at the SP2 version with the latest hotfix 09.00.0000.7423, but I assume most are.

Bye, Olaf.
 

At the moment I have the option of "Ctrl Home/End" or just "Home/End". I think I will leave it like that unless I find other issues.

My VFP Version is SP2 09.00.0000.5815 I've not found a link to download 09.00.0000.7423 the last Hotfix.

Regards,

David.

Recreational user of VFP.
 
How strange, I've just noticed that whilst using the VFP IDE that I am subconsciously using Ctrl Home / Ctrl End to Navigate around. I suppose in my application (Amateur Radio Logbook) I use Page Up, Page Down so the Home/End Keys would make for smother operation. Several Commercial Logbooks that I've used in the past also use Home/End to get from Top to Bottom of Logbook.

Regards,

David.

Recreational user of VFP.
 
Yes, I agree supporting both ways is a good solution, nobody would be surprised or miss an option.

Most browser windows also react to HOME/END (unless your text cursor is in a text area), Word lets you go to begin and end of line, Excel does also react differently, so there is no consistent and simple behaviour, both Word and Excel do react to CTRL+HOME/END, so there is some truth, but no final, maybe whenever you have no text cursor yet, you can also scroll without CTRL.

As VFP support ended, you don't find much anymore, but the hotfixes are kept for example in VFPXs GitHub repository:

You don't need Hotfixes1+2, as they are cumulative. Notice anyway: After the hotfix EXE ran, read the readme and follow instructions, it does not replace files automatically, it mainly just extracts an archive of fixed files and asks you to put them into their respective places, as it's "just" a hotfix and not a service pack.

It'd be interesting if this changes your behavior, but even if not you would gain some fixes.

Bye, Olaf.
 
All these years, I've been putting home and end buttons near the bottom of my grids.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top