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!

Positioning in a grid in response to a character entered.

Status
Not open for further replies.

AndrewMozley

Programmer
Oct 15, 2005
621
GB
I have a grid where I can Key “B” <Enter> into Column7.text1. If I do this, the Valid() method does various things and then moves focus to Column 6 with :

KEYBOARD '{LEFTARROW}'

This works. I would however like to take this action without the user have to press <Enter>. Have tried setting the input mask of Column7.text1 to “A”, but find that I still need to press the <Enter> key. So I have then included code in the “InteractiveChange” method to invoke the Valid() method immediately.

This works as far as taking immediate action is concerned. But I am finding that the KEYBOARD '{LEFTARROW}' is no longer having the desired effect, even though the Interactive change() method is detecting this and exiting immediately with DoDefault().

I feel that I am probably overcomplicating things. How can I arrange that a text box in a grid responds to a single character, and (for one of these characters), causes the position on the grid to move to a different column (in this case, the one to the immediate left)?

Thanks.


 
The easiest way to do this is probably something like this:

[tt]Grid1.ActivateCell(Grid1.ActiveRow, 6)[/tt]

That will move the focus from column 7 to column 6.

Also, I'd suggest that you don't use the Valid event for this. InteractiveChange would be better.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thank you Mike.

I have put the code into the InteractiveChange() method. Your suggestion works up to a point. If the top line of the grid is the first record of the underlying cursor, it achieves the result. But I find that if the grid has been scrolled down, so that the first displayed line is (say) the 3rd line in the cursor, then the

Code:
.grdmain.ActivateCell(.grdmain.ActiveRow, 6)
. . . highlights a cell a few rows below what had been the current row.

I have found the these instructions - still in InteractiveChange() – seems to achieve the result.

Code:
WITH Thisform
   . . . .
   (Test for a particular character being entered)
   . . .
   .grdmain.column6.enabled = .T.
   .grdmain.Columns(6).setfocus
   This.Valid()
   ENDWITH
RETURN DODEFAULT()

The This.valid() instruction is included to allow the entry of a single character to cause the desired result (enable the cell in Column 6 and reposition on it). But if there is a better way of doing this, I would appreciate guidance.

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top