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

Set Grid Header Click Method 2

Status
Not open for further replies.

JRB-Bldr

Programmer
May 17, 2001
3,281
US
OK, I got the help I needed for my previous questions, now the next one.

I am dynamically building the Grid in the Init Method of my Form. I am using the SELECT table and AFIELDS() to get its field count and field names.

I am using the field count and field names to dynamically set the Grid.Column.Count and then with a FOR ENDFOR loop I am setting up each Column.

SELECT MyTable
=AFIELDS(aryFlds)
mnFldCnt = ALEN(aryFlds,1)

ThisForm.Grid.ColumnCount = mnFldCnt

FOR i = 1 TO mnFldCnt
mcFldName = aryFlds(i,1)

* --- Set Column Control Source ---
mcControlSource = ALIAS() + "." + mcFldName
mcObject = "ThisForm.Grid.Column" + ALLTRIM(STR(i)) + ".ControlSource"
&mcObject = mcControlSource

* --- Set Column Header Properties ---
mcObjBase = "ThisForm.Grid.Column" + ALLTRIM(STR(i)) + ".Header1."
mcObject = mcObjBase + "FontBold"
&mcObject = .T.
mcObject = mcObjBase + "Alignment"
&mcObject = 2
mcObject = mcObjBase + "Caption"
&mcObject = mcFldName
ENDFOR

Now I want to put code (the same code) into the HEADER's Click Method.

Into each Header Click Method I want to put code to call the Form's SetOrder method:
ThisForm.SetOrder

How do I programatically get this code into each one?

Thanks,
JRB-Bldr
 
Issue #1

The "This" will point to your form, because it is used in the "THISFORM.reorder()" method. To refer to the grid you have a couple choices....one is to refer to it in your code as thisform.Grid1.column2.controlsource and the other (and better way is to send the header object in as a parameter, in which case you would make a call from the headers' double-click event that reads something like thisform.reorder(this.parent) and then you would need to add a "lparameters tcColumn" statement to your reorder method and use tcColumn.controlsource

...Give that a shot.

#2 Filter

Filter's aren't really enforced after you issue a set filter until the recordpointer moves...most will use either LOCATE or GO TOP in order to get a filter enforced...try that and if you still see records in there that your grid isn't displaying then try to reset the grid's recordsource and/or refresh() the grid.

boyd.gif

craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Thanks Craig.

Issue #1
I'll try it like you suggest.

I find it interesting that before when I had 'hard coded' in the separate Column.Header1.DblClick method's code, the "This.Parent" worked well.
Now, with the code being dynamically inserted, it no longer 'understands' THIS and, consequently, no longer works.

Issue #2
In the interim I already figured this one out.
The Filter was using variables which were not PUBLIC across the Form. Just a memory 'flash back' to the 'good old days' when SCOPE was sufficient to carry variable values across all Screen Snippets.

Thanks,
JRB-Bldr
 
On Issue #1, what you were doing before was running code IN THE HEADER'S DBLCLICK METHOD, so "this.parent" was the parent of the header, which would be the column. When your code is in the Reorder method, that's a method OF THE FORM. THE FORM HAS NO PARENT!

On Issue #2, DON'T declare your variables as PUBLIC. Use Form Properties instead. You can create your own form properties from the Form Designer by clicking on the Form menu pad and selecting the New Property option.


-BP (Barbara Peisch)
 
Barbara -
Whenever I have used the VFP7 Form Designer's -- Form | New Property... (from the top menu) and added a New Property to the Form it has appeared in the Form's Properties as a Logical property.

Even attempting to use the Form Designer's -- Edit Property/Method has not shown me any way to change the Type of this New Property/Variable.

I am open to hearing out to change the New Property to a different Type.

Thanks,
JRB-Bldr
 
go to the property and type in a value or set the value to whatever you want in code...

So at design time if it is going to be a string then blank it out (none), and if it is going to be a numeric value then put something like a 0 in it, and if it is a logical then you already have what you need.

Remember that VFP is not a strongly typed language so these things are possible.

boyd.gif

craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top