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!

How Do I save current cell's contents to var on grid's click event 1

Status
Not open for further replies.

drosenkranz

Programmer
Sep 13, 2000
360
US
I'm new to VFP. I have a grid who's source is an sql select statement. I want the user to be able to either click on the cell or tab to the cell in the grid control and press enter to select the row of the grid that contains their item. On that (click?) event, I want to save the value to a gc_var so I can load another form with an sql select based upon that same gc_var from the grid.

How would I save that cell's value to the gc_var?

The Click and DblClick events don't appear to work on my grid's control... why?

 
drosenkranz

To save a cell's value to a variable, in the .Valid() event of the cell put:-

gc_var = THIS.Value

If you place code in the events of a grid's container, ie THISFORM.Grid1.Click() or THISFORM.Grid1.DblClick(), they will only fire if the grid's container is accessible.

Thus if you have a grid sized to show 10 records, but only have only 5 records showing, the bottom half of the grid will react to a click or double click, as the container is accessible.

But if you click or double click on a record in the top half, you are in fact clicking on a cell, ie THISFORM.Grid1.Column1.Text1.Click() or THISFORM.Grid1.Column1.Text1.DblClick().

If the code you want executed is not in the correct event, this may be your problem.

Hope this helps

Chris
 
Thanks Chris, I appreciate the info but I'm not sure I follow part of your example.

If the top half of the grid in your example won't accept a Click because they are cells, then why would repositioning to the "records at the bottom" allow the Click Event to work? If you saying the cells are receiving the Click events then why wouldn't the "records at the bottom" also act like cells?

I did notice clicking in the blank column to the right of my data did accept the Click Event. Is this because this is actually the grid's area that is not a cell?
 
drosenkranz

If you click or double click on a cell in grid in a row containing a record, even if the record is empty, then you are clicking on the cell.

A click anywhere else within in a grid, excluding headers, means you are clicking on the container, so when you click on what appears to be a cell beyond the total number of cells, (fields), in a row, it also means you are also clicking on the container.

If you move the code you want executing to the cell, for example THISFORM.grid1.column1.text1.click() event, then you will find the code will execute.

It appears from your original description of your problem, that you had simply placed your code in the wrong event, and you were expecting THISFORM.grid1.click() to react to a click on a cell.

I hope this explanation helps, if not please advise.

Chris

 
Chris,

I've got the picture now. This part of app is working correctly now. Thanks for all of your time and energy.

Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top