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

Grid Click Events... virtually useless?

Status
Not open for further replies.

tristero

Programmer
Jan 24, 2003
95
US
is there a work around for click events in a grid? is it possible to trigger a click event by clicking on a record?

or is this a weakness in vfp?
 
A click event in a grid is for the entire grid object. If you want to fire a click event on an individual field/cell, you need to program the click event for the control of that field. I.e., thisform.grid1.column1.text1.


-Dave S.-
[cheers]
Even more Fox stuff at:
 
I can't even get a click event to fire at all... according to one reference i have, the grid.click event only fires when you click on an empty area of the grid with no info (essentially at EOF).

i want to be able to trigger a click even just from clicking anywhere on the grid... any ideas?
 
As long as there are records displayed in the grid, the click event for the underlying control will fire, not the grid click event.
If you scroll the grid to the very end of the records, so that there are empty rows displayed on the grid, basically after EOF(), the grid's click event will fire. If you are over a field containing data, you can't get the grid click to fire. Only the text (or whatever) control's click event.
Code:
---------------------------------------
xxxxxxxxxx|xxxxxxxxxx|xxxxxxx|xxxxxxxx|  <-- text1.click fires
---------------------------------------
xxxxxxxxxx|xxxxxxxxxx|xxxxxxx|xxxxxxxx|
---------------------------------------
xxxxxxxxxx|xxxxxxxxxx|xxxxxxx|xxxxxxxx|
---------------------------------------
          |          |       |        |  <-- grid click fires
---------------------------------------
          |          |       |        |
---------------------------------------

-Dave S.-
[cheers]
Even more Fox stuff at:
 
To expand on Dave's answer, it's a good idea to put the code you want to run in the grid's click method. You need to make sure the textboxes in each column call the grid's click from their own click. I do this by having a special textbox subclass that is used only in grids, with this.parent.parent.click() in the click method.



-BP
 
BPeisch:

I'm curious how you've subclassed the grid?
I realize you said you subclass the textboxes.

Did you create a grid subclass that reloads the textboxes
with your own textbox class on initialization?

Just curious.

Darrell
 
Did you create a grid subclass that reloads the textboxes
with your own textbox class on initialization?


Nope. I do that at design time. You can delete the default textbox that ends up in each column by selecting it from the property sheet, then clicking on the grid and hitting the Delete button. You can also add as many controls as you like to each column by making sure the grid is in edit mode (it gets those cyan hash marks around it), then clicking on a control on the Form Controls Toolbar and clicking the column you want it in.

BTW, if you're using VFP 8, you can use BindEvent() instead of a subclassed textbox to do the same thing. You would need to create a class for handling events. I put this kind of thing in a PRG based class. Then, in the Init of your grid class:
Code:
FOR EACH loColumn IN This.Columns 
  FOR EACH loControl IN loColumn.Controls
    IF LOWER( loControl.BaseClass ) = 'textbox'
      BINDEVENT( loControl, 'Click', This, 'Click' )
    ENDIF
  ENDFOR
ENDFOR
(Marcia Akins reminded me of this technique today on CompuServe.)



-BP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top