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!

ActivateCell does not activate cells outside grid display

Status
Not open for further replies.

DirkVFP

Programmer
Aug 25, 2005
57
NL
Hi all,

Searching the forum I found this topic:
My problem seems to be the same, except I already use the workaround Mike proposed there (and it doesn't work):
Code:
Thisform.gridResult.ActivateCell(nIndex,nColumn)
Thisform.gridResult.SetFocus()

When I reach the last visible row and hit the down arrow button, the grid scrolls one row down (eg. the next row becomes visible) but I cannot activate the next cell. No errors, no nothing. It just won't work. Resizing the grid does solve the problem, but resizing the grid is not an option.

Maybe it has something to do with the way I'm using the textbox's KeyPress event:
Code:
********** DOWN **********
IF nKeyCode = 24 THEN 
	*** Get current position in grid
	Thisform.get_grid_pos()

	*** Check if an update is needed
	IF nPreviousValue <> This.Value THEN 
		Thisform.update_value("order",This.Value)
	ENDIF 
	
	*** When user presses down arrow key, move to next record in grid
	*** If this is the last record, move to the first in grid
	IF (pnIndex + 1) <= RECCOUNT("result") THEN
		pnIndex = pnIndex + 1
	ELSE 
		pnIndex = 1
	ENDIF 		
		
	*** Update grid control
	Thisform.gridResult.ActivateCell(pnIndex,pnColumn)
	Thisform.gridResult.SetFocus()
	
	*** No default behaviour of down arrow key wanted
	NODEFAULT 	
ENDIF
 
Code:
********** DOWN **********
IF nKeyCode = 24 THEN
    *** Get current position in grid
    Thisform.get_grid_pos()

    *** Check if an update is needed
    IF nPreviousValue <> This.Value THEN
        Thisform.update_value("order",This.Value)
    ENDIF
    
    *** When user presses down arrow key, move to next record in grid
    *** If this is the last record, move to the first in grid
    IF (pnIndex + 1) <= RECCOUNT("result") THEN
        pnIndex = pnIndex + 1
    ELSE
        pnIndex = 1
    ENDIF         
        
    *** Update grid control
    *** Activate Grid BEFORE Activate Cell
    Thisform.gridResult.SetFocus()
    Thisform.gridResult.ActivateCell(pnIndex,pnColumn)

**** Also you could try:    
*** GOTO pnIndex IN Result
*** thisform.gridResult.Columns(pnColumn).SetFocus()
**** but this is not tested


    *** No default behaviour of down arrow key wanted
    NODEFAULT     
ENDIF

Borislav Borissov
 
Hi Dirk.

When I reach the last visible row and hit the down arrow button, the grid scrolls one row down (eg. the next row becomes visible) but I cannot activate the next cell. No errors, no nothing. It just won't work. Resizing the grid does solve the problem, but resizing the grid is not an option.

Forgive me if I am missing something obvious and asking a really stupid question, but why are you writing code to handle this. When you press the down arrow key in a text box in a grid, the native behavior is to move to the next row in the grid. The grid scrolls automatically is you are on the last line in the visible portion.

Marcia G. Akins
 
Forgive me if I am missing something obvious and asking a really stupid question, but why are you writing code to handle this. When you press the down arrow key in a text box in a grid, the native behavior is to move to the next row in the grid. The grid scrolls automatically is you are on the last line in the visible portion.

Marcia,

The default behaviour of the grid control simply does not co-op with the wishes of our customer. There's some more control wanted and by handling the KeyPress events that control becomes possible.
 
Boris,

I will try your suggestion, will post my findings if I got any.
 
Marcia,

About this default behaviour: whenever a textbox in a grid receives focus I call This.SetFocus so all the text within the textbox is selected. I have not found another way to accomplish this (SelStart/SelLength do not seem to work).

But focussing results in a flashin scrollbar and also the highlight of the current record flashes. This unwanted behaviour can be prevented by handling the keypress event (and the activating of the next cell) by yourself, locking the form during the event. The result is a smooth scrolling grid and that is what our customer wants.

If you got other methods of selecting all text in a grid, please let me know :)
 
About this default behaviour: whenever a textbox in a grid receives focus I call This.SetFocus so all the text within the textbox is selected. I have not found another way to accomplish this (SelStart/SelLength do not seem to work).

As long as you do not need to handle the text box's dblClick() event, this code in the textbox's click event should handle it for you:

Code:
Textbox::Click()
This.SelStart = 0
This.SelLength = LEN( This.Text )
NODEFAULT

Marcia G. Akins
 
Marcia,

Thank you, the code you supplied does the trick. Last time I tried, I could not get it working, however I used this code:
Code:
This.SelStart = 0
This.SelLength = LEN(ALLTRIM(STR(This.Value))) && Numeric values in there
NODEFAULT

And this does not work. I used both methods and your LEN(This.Text) returns 6 characters (propably including spaces) and mine returned 1 (which seems correct since there is only a value in there with length = 1).

The only thing left is that I can see that all the text gets selected, which I want to prevent. When a user clicks a field it should get highlighted immediately. What's a good approach to get that done? I tried locking the form, but that doesn't help much.
 
I've (finally) found out why ActivateCell does not work outside the visible cells. That is because ActivateCell uses RELATIVE cell positions (thank you Microsoft for NOT mentioning this anywhere in the help file).

I've written a small function to determine the relative position in the grid and all works fine now.
 
Dirk,
You could report that HELP omission to the MS. Just click on the link (at the bottom of the page in HELP) and report it.


Borislav Borissov
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top