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!

Double-clicking in a grid 2

Status
Not open for further replies.

Mike Lewis

Programmer
Jan 10, 2003
17,516
Scotland
I've just made a happy discovery which I thought I'd share.

I've often had difficulty trapping double-clicks in a grid. If the user double-clicks in a cell, it is the DblClick of the textbox within the column that fires. If they double-click in a blank part of the grid, the DblClick of the grid itself fires. (The same is true of single clicks and right clicks, of course.)

Apart from the trouble of having to trap multiple DblClick events, this raises a problem. If you don't bind the grid to a recordsource until runtime, the column objects don't exist at design time, so there is no way to write code in their event-handlers.

It turns out that if you set the grid's AllowCellSelection to .F. (this property is new in VFP 8.0), then the individual textbox never gets focus, so it is always the grid's DblClick that fires. That makes it much easier to write code to trap the event, since you only have to write the code in one place, and the grid's DblClick is always available at design time.

What's more, the act of double-clicking also selects a record, so you can still use the record number to find out which row the user double-clicked on. (Unfortunately, that doesn't apply if they click in an empty portion of the grid.)

Mike




Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Star worthy suggestion and solution. Thanks Mike.

boyd.gif

craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
So how do you handle the situation where they double click on an area in the grid (let's say row #5) but only 2 records are in the table?
 
Clarkpro,

So how do you handle the situation where they double click on an area in the grid (let's say row #5) but only 2 records are in the table?

Good question. Don't know the answer.

You can look at the record number to see which row was highlighted, and act on that one. But that's not very good user interface design.

Anyone got any ideas?

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Hi Mike.

>> You can look at the record number to see which row was highlighted, and act on that one. But that's not very good user interface design. <<

What makes you say so? Do you see a problem with code like this in the dblClick():

Code:
IF RECNO( This.RecordSource ) > 0
  MyForm.DoSomething()
ENDIF


Marcia G. Akins
 
Hi Marcia,

No, I don't see a problem with the code -- only with the user's perception

If the user double-clicks in a "blank" row, the record number will still be set to the record that the highlight is on. As far as the form is concerned, that's the record that the user wants to do something with. But it's not the one the user double-clicked on.

OK, so you're going to ask my why on earth the user would double-click in a blank row in the first place. I don't know. The point is that you can't stop them from doing it, and you can't (easily) detect it if they do.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
So how do you handle the situation where they double click on an area in the grid (let's say row #5) but only 2 records are in the table?
...why on earth the user would double-click in a blank row in the first place. I don't know.


I guess I know why. Possibly, to enter some information in row #5, while leaving row #3 blank for better readability and reserving row #4 for later use - Excel, Word, and other analogies sometimes are very strong.

Not sure how to deal with it, though.

 
Stella,

Thanks for your input. I see your point. However, the whole point of this technique is that you need the grid's AllowCellSelection to be .F., which means that the grid will be read-only, so the user wouldn't be able to enter any data anyway. Still, it's an interesting thought.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Mike,

I understand. I was saying what users could be trying to do, not what they are actually allowed to do. They expect thing to behave in a certain way to which they are used, but aren't we all?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top