Example of a code for VFP 8.0 (or later), showing use of properties: HeaderClassLibrary and HeaderClass a column in Grid. On an example of the class, derived from Header, the opportunity of change of the order of sorting on click on header of a column in Grid is shown.

Some comments to properties and code of example:

- Instance of class CursorAdapter placed in DataEnvironment of the form (Form design menu item: View/Data Environment....) and there the class caCustomers, derived from CursorAdapter is used. 
- This (caCustomers) is adjusted for work with VFP-tables, since caCustomers.UseDeDataSource = .T. and DataEnvironment.DataSourceType ='NATIVE', see also code event DataEnvironment.BeforeOpenTables() (- opening VFP-dbc file) and property caCustomers.SelectCmd ='select CUSTOMERID, COMPANYNAME from CUSTOMERS') (that it is chosen) in the cursor caCustomers.Alias ='curCustomers' 
- All this can be seen on the right click through menu item Builder... for selected object... 

... As a result of SQL-SELECT, we have the VFP-cursor curCustomers with the demanded fields... 

Thus it is obvious, that: 

- This cursor (curCustomers) it is natural at the moment of the first opening has no indexes 
- On click on any header of a column in grid the code from progs/utilites.prg is carried out and there completes{develops} method Click () from class MyHeader, allowing "on fly" to create indexes (in a temporary cdx-file) for fields from matching columns if it is is possible and if such still it has not been created earlier. Otherwise, if the index already exists, resetting of an active index is simply made. 

In class MyHeader (progs/utilites.prg) there is a series of methods both for "internal" work, and for use "from the outside": 

- GetAlias() - allows to gain the alias used as a source of data for the matching instance of the class-header  
- GetCdxFile(tcAlias) - gains the name of a cdx-file from a name of a dbf-file at an alias of the table tcAlias, passed as parameter 
- DeleteCdxFile(tcAlias) - accordingly deletes a cdx-file for an alias passed as parameter (if such is available) (Pay attention, that it is used in event MyHeader.Destroy() to delete a temporary Cdx-file at destruction of class instance, i.e. on closing of the form) 
- ClearAllPictures() - "removes pictures" at all headers of grid  
- RemoveAllTags(tbDeleteCdxFile) - set order to 0, and if tbDeleteCdxFile=.T. also deletes the temporary Cdx-file used of the given instance of class-header at grid 


It is necessary to note also, that:

- First, "it" works only for version VFP 8 and later, and only if has been added/is changed in Form design (In the documentation: HeaderClass Property... At run time, changing the HeaderClassLibrary and HeaderClass properties at run time does not affect the header.) 
- Secondly, the class which contains definition of your MyHeader-class, should be presented in a prg-file (not vcx). (In the documentation: HeaderClassLibrary... Visual FoxPro includes the HeaderClassLibrary program (.prg) in the project during a project build.) 
- At last, to change property MyForm.MyGrid.AnyColumn.HeaderClassLibrary, there is enough in Properties Window, having chosen in overhead ComboBox matching Column-installation, having moved on it property [All/Other]HeaderClassLibrary to stick in originated thus in the overhead part the button [...], and in the originated dialogue to choose a matching prg-file, and in it and the matching Header-class... 

Best regards.
Michael Drozdov, ICS Soft, Perm, Russia
My Page: http://vfpdev.narod.ru/