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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grid Got Focus

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
US
Is there a way to simulate a grid got focus event in VFP6. What I'm trying to do is to always set focus to the same column when tabbing into the grid. I thought about writing some code and reference it in each textbox in the grid and set the proper focus from there. Even thought about using an invisible control and using it to set the focus. Just wondering if someone has done something like this before.

Auguy
 
Hi Auguy,

The Grid's GotFocus should fire when the user tabs onto it. So I am unclear as to why you would need to simulate it.

pamela
 
Pamela, I don't see a Got Focus event for the grid control in VFP 6 or 9. I only see Got Focus events on the controls in each column. Am I missing something obvious here?

Auguy
 
I think I found a solution to always setting focus to the same column when tabbing into the grid. I hid a textbox control behind the grid and put Thisform.GridName.ColumnName.Setfocus() in the Gotfocus of the hidden control. I also set the tab order so the hidden textbox is just before the grid. This may not be great coding, but it solves the problem. Are there any downsides to doing it this way?

Auguy
 
Mike,

Only when the user tabs into the grid. This is an order entry form and the client wants the focus to be set to the Qty column when tabbing into the form to make data entry easier using the keyboard. The other columns (part number, price, description, etc.) will receive focus at some time during the entry process. It is also ok if the user clicks on any column in the grid.

Auguy
 
Hi Auguy,

the grid has no got/lostfocus, but it has the when and the valid event.

Besides that you could use the AfterRowColChange Event to set focus to the column you want.

The logic would go this way:
In the When event you set some grid property true, so you know in the following AfterRowColChange, that it is caused by the grid getting focus, not by tabbing within the grid from column to column.

Yo in AfterRowColChange you check for true in that property and set it to false and setfocus to the column you wish.

Bye, Olaf.
 
Thanks Olaf, I was thinking about something along that line of thought. Thanks to everyone for their assistance with this issue!

Auguy
 
Hello Auguy:
Not very elegent, but this is a quick and dirty method. You will have to fine tune.

****Grid When()
**** Column to receive focus when tabbing = 3
nCol = this.leftcolumn
this.activatecell(1,iif(ncol = 1,3,(((ncol-3)*-1)+1)))

The reason for the IIF is if the user moves towards the end of the grid, Column 3 becomes the 3rd column visible. We need to send it back to the actual column 3

I am sure there is a better way but it does not come to mind

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top