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 Right Click event 1

Status
Not open for further replies.

ezpzjohn

Programmer
Jun 29, 2001
50
GB
Hi All

I am trying to get a shortcut menu to work on a form that has a grid on it.

Tried using the right click event on the form which worked fine unless you were over the grid in which case nothing happened.

Then put code in the right click event of the grid and nothing happened.

Found I had to put the code in every right click event for each column's current control to get it to work.

Is this normal or am I missing something?

John
 
I found I had to do that as well to get the same thing to work so you're not alone!

Neil "I love work. I can sit and stare at it for hours..."
 
ezpzjohn

Is this normal or am I missing something?

Its normal. You will notice that if you have a grid that has "some" information (the grid is half filled), if you have some code in the rightclick event of the grid, and you rightclick in the part of the grid that doesn't have data, the rightclick of the grid is the one that triggers, not the column one. That is because when there is no data the grid has control, and when there is data the column has the control.
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first or check this link
 
John,
Well, ditto here, but to make code changes easier, I only put the code in the first grid column, then in every other grid column, I actually call the first columns Right Click event. That way, if I have to make changes to the code, I still only have to do it in one place. I do the same thing for single click in grids. (I often allow users to select a record from a grid, and invariably, they'll have their mouse cursor over the 3rd or 4th columns... so, I had to do something.
If you haven't done it this way, you might want to consider it, as I said, makes keeping the code under control that much easier.

Best Regards,
Scott

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Thanks to Neil, Mike and Scott for your responses.

It's a pain about the extra coding required but Scott's is a good tip on referencing other columns to the RightClick event of the first column to make code changing more managable.

I've done it by adding another method to the form and calling that method from each column, but Scott's suggestion saves the addition of that extra method.

John
 
I got a followup to this question.

since i encountered the same problem with doubleclicks on gridrecords. i placed the code in every text field (a reference to a procedure).

but when i rebuild the grid again. e.g. certain values have changed and i put the controlsource again to it. even so with the header caption. i loose my methods.

any ideas to preventing this? since i cant assign methods runtime to these properties (they are readonly-runtime)

thanks
 
poeijer

If you have methods in your grid and you "reconstruct" you grid as you found out it is no longer the original grid, but a different version. In order to avoid loosing you methods you have to also put them back. So when it comes time to "change certain values", you have to create a method that "totally" rebuilds you grid including the methods. Here is an simple example (by code) to add a grid and add a textbox to the grid's column1 (with a method):
Code:
Public oform1
oform1=Newobject("form1")
oform1.AddObject("grid2","grid2")
oform1.grid2.column1.AddObject("text2","text2")
oform1.grid2.column1.CurrentControl="text2"
oform1.Show
Return
Define Class form1 As Form
	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"
	Procedure Load
	Create Cursor myCursor (Name c(20))
	Insert Into myCursor (Name) Values ("Mike")
	Go Top
Endproc
Enddefine
Define Class grid2 As Grid
	ColumnCount = 1
	Height = 169
	Left = 24
	Top = 36
	Width = 313
	Name = "Grid1"
	Visible = .t.
	column1.Name = "Column1"
Enddefine
Define Class text2 As TextBox
	Visible = .T.
	Procedure DblClick
	Messagebox("Hello grid")
Endproc
Enddefine
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top