# Tuesday, November 25, 2008

The Visual FoxPro Grid Control
I've often been heard to say that Visual FoxPro's grid is one of the greatest controls ever devised. I still feel that way, but wouldn't it be nice if some of the functionality that our customers want implemented in the grid came stock? You know, features like: sorting, filtering, incremental search, saving user preferences, and exporting to Excel. It'd be even cooler if this type of functionality could be implemented on any Visual FoxPro grid (regardless of the recordsource) by simply dropping a class on a form, setting a single property and writing a single line of code. Well, that's what I have set out to create with the class I present in this blog entry.

First Shown at Southwest Fox 2008
At Southwest Fox 2008, I presented a session entitled "Creating a Professional VFP Application from Start to Finish" in which I showed an earlier version of GridExtras. I've improved on it since then, so if you attended Southwest Fox 2008 you may want to get the control and sample from here rather than the session download. For those of you that didn't attend Southwest Fox 2008 (you should have - it was a blast!), you can see the basic functionality provided by GridExtras in the screenshots provided at the bottom of this blog entry.

How to Use the Class
I've provided a sample.exe application in the download so you can try it out and see how it's implemented. However, the basic steps are:

  • Drop an instance of the gridextras onto your form or container (one gridextras for each grid you want to enhance).
  • Set the GridExtras' GridExpression property to a string that will evaluate at runtime to the grid you are enhancing - "Thisform.Grid1" is the default value for this property.
  • Call the GridExtras' Setup() method whenever your grid is ready to go. I have no way of knowing if you are setting the recordsource at runtime, or whether you are adding columns in code, so this method is provided as a way for you to control when GridExtras will begin interacting with the grid.

That's all there is to getting GridExtras up and running for a grid in your application. As I say, I've included a sample in the download, so if you have any questions about how this is done just review the sample or you can post a comment here on my blog and I'll do my best to answer it.

Other Properties of Note
There are a few other GridExtras properties you may want to take note of and use, such as:

  • CompanyName and ProductName - these properties are used to determine where to save the user's grid preferences file which is profile isolated (C:\Users\Craig\AppData\Roaming\MyCompany\MyProduct\gridprefs.tmp on Vista or  C:\Documents and Settings\Craig\Application Data\MyCompany\MyProduct\gridprefs.tmp on Windows XP)
  • AllowGridExport, AllowGridFilter, AllowGridPreferences, AllowGridSort - these properties allow you to turn certain features of the class off or on depending on your needs.
  • TemplateTable - this property determines where GridExtras looks for the gridextras.dbf which is used to save the grid templates the user creates (user can save their filters and sorts to be able to easily recreate them at a later time). This property may need to be set if you plan to keep the gridextras table out on a network path such as with the shared database folder for your application.

What's Next
Just have fun with GridExtras and see if it's useful to you and your applications. In a perfect world, you'd find some way to improve it (add additional export formats, provide a column lock feature, etc.). If you do improve GridExtras, I'd appreciate it if you would contact me and share the improvements you've implemented. Thank you in advanced to those of you that decide to do so.

Until next time... Visual FoxPro Rocks!

Download GridExtras and Sample (approx. 170 KB)

Figure 1: GridExtras provides sorting, incremental search, and filtering capabilities to any Visual FoxPro grid.


Figure 2: GridExtras has additional features such as the ability to go semi-transparent and the ability to save the user's preferences (column order and width).


Figure 3: In addition to the features provided by GridExtras through a grid's column headers, there is also an icon added to the bottom right of the grid that allows the user to access the "Grid Templates and Export" screen seen in Figure 4.


Figure 4: The grid templates help the user save grid views so they can recreate them quickly in the future. The export feature of GridExtras can create XLS, XLSX, XLB, and XLM Excel formats. The grid's header captions are used to name the Excel columns when data is exported.


Tuesday, November 25, 2008 12:00:52 AM (GMT Standard Time, UTC+00:00)  #    Comments [12]



<April 2014>