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

Selecting a row from a grid 1

Status
Not open for further replies.

AndrewMozley

Programmer
Oct 15, 2005
621
GB
I have a grid where I display details of customers that the user might be interested in. These columns are be Account, Name, PostCode, Contact

In my first version I wanted the user to be able to double-click on a row (a customer) to select that customer, and I tried including the relevant code in mygrid.dbclick().

This did not work, because a double-click on a cell is interpreted as just that : The double click does not percolate through to mygrid.dbclick().

So I changed the code to pick it up in mygrid.Column1.text1.DblClick(); and that produces a result - provided that the user double-clicked on the first column.

However, I would still like the user to be able to select a particular customer by some action on any column of the grid. So I put code into mygrid.beforeRowColChange() and tested for LASTKEY() = 13. This works up to a point. The event does indeed occur and I can treat it as selection of the customer.

But if the last action before entering the grid was pressing the <Enter> Key, if I subsequently click (Single click) on a cell, that invokes the BeforeRowColChange() method. And this finds that LASTKEY() was 13 - it has not been affected by the last mouse click.

So my code treats the user's action as the selection of that customer. That is not what I wanted. I only want to treat it as selection of the customer if the user has pressed the <Enter> key while the grid is being displayed.

As always, grateful . . .
 
You're almost there by putting the code in the grid::douleclick().

What you need is for each textbox to pass the double-click along: this.parent.parent.doubleclick(). (The textbox's parent is the column, the column's parent is the grid, so this.parent.parent.)

The best way to pull this off is, as it happens, also the easiest way. DON'T USE DEFAULT CONTROLS. Build your own control classes and use those instead. In this case, you only need a textbox class with the generic code above and plop it into each column in your grid. Job done. Drop mic.

An alternative might be to use BindEvent() to have the grid respond to control events, but I'm opposed to using BindEvent() to subvert the event/inheritance/containership models rather than to augment them.
 
Wouldn't AfterRowColChange be the better event, it happens in the row you end on and then the recordpointer is your selected customer.

Bye, Olaf.
 
Does the grid need to be editable? If not, a simple solution would be to set the grid's ReadOnly to .T. and its AllowCellSelection to .F. That way, the contained controls won't receive the event, and you can simply write your code in the grid's DblClick.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top