Browse DevX
Sign up for e-mail newsletters from DevX


VFP 8 Feature Highlights : Page 4

There are so many new features in VFP 8 that we can't cover them all. Claudio does his best to hit the high points in this round-up of several exciting new capabilities that VFP 8 brings to the table.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Acting Like MS-Excel
Everyone who uses MS-Excel is used to the way it works in regarding to resizing columns (auto-fitting the columns to match their largest content), which can be done by double clicking in the line that divides one column from another, causing the column at the left to be resized. Alternatively, we can double click the square at the left-top of the spreadsheet and that will cause all the columns to be resized.

VFP's Grid now behaves just the same. You can see in Figure 4, between the "Contact Name" and "Contact Title" column headers, the mouse pointer indicating the divider line. After double clicking, the "Contact Name" column is resized.

Not just that: we can also Auto-fit columns in the grid programmatically:

   *-- Resize second column of the grid
   *-- Resize fourth column of the grid
   *-- Resize all of the columns at once
This feature (and some other new features) also works with the BROWSE command. For example:

   BROWSE Name oMyBrowse NoWait
Another Excel-like feature is the ability to freeze columns. In Figure 4 we see a thicker line dividing the "Contact Title" and the "Country" columns. That line indicates that all the columns at the left side of it are frozen. When scrolling to the right side of the grid, we will never lose sight of them. Here is the code required to freeze the first four columns of the sample grid:

Grid Highlighting
VFP developers have always had trouble working with highlighted rows in a grid. End-users want the ability to select a row in a grid and keep track visually of which row is selected, even when the focus is in another place (see the third line of the grid in Figure 4). We usually end up writing a whole bunch of code to make that work. Now, this line of code is all we need:

   Thisform.grdCustomer.HighlightStyle = 2
Also, we have two properties to configure the backcolor and forecolor of the highlighted row: HighlightBackColor and HighlightForeColor.

A Grid as a ListBox 
Previously, if we clicked in a row of the grid, the row would be highlighted and the cursor would be blinking inside the cell (usually in a textbox). Sometimes we do not want the user to have access to the cell. Rather, we just want the user selecting a record, imitating a ListBox (remember that a ListBox does not has the Grid's capabilities to bind to data, among other things).

To address that, there is another welcomed new property to the Grid: AllowCellSelection.

   *-- Do not allow the user to select cells.
   Thisform.grdCustomers.AllowCellSelection = .F.
Hiding and Showing Columns
Another feature that used to require several lines of code is hiding and showing columns in a grid. There was not a single straight-forward way to do that. Now, all it takes is:

   *-- Hide second Column
   Thisform.grdCustomers.Columns(2).Visible = .F.
   *-- Show fourth Column
   Thisform.grdCustomers.Columns(4).Visible = .T.
This makes it very easy to show or hide columns depending on the user rights to see certain data, for example.

Centering Checkboxes
Often, grids are used to allow the user to select one or multiple records (look at the "Select" column in Figure 4). In those situations, we insert a Checkbox in a column of the Grid, and guess what? We cannot make the Checkbox center itself within the column. The workaround was to insert the Checkbox centered in a Container, and then insert the container into the column.

Once again, we can reduce that now to a single line of code by using the Centered property of the Checkbox (I did split it here in three lines to fit the layout of the magazine):

   *-- Centralize the Checkbox the eighth column.
   With Thisform.grdCostumers
       .Columns(8).chkSelect.Centered = .T.
Images on the Headers
Last but not least, we see that two columns have images on their headers (columns "Company Name" and "Phone"). To add an image to a header we set the Picture property:

   With Thisoform.grdCustomer
       .Columns(2).Header1.Picture = "Customer.ico"
       .Columns(6).Header1.Picture  = "Phone.ico"
You may have noticed that I am using an ICO file (which is an icon image) instead of a BMP or other graphics image. See the sidebar GDI+ Support for more information about this.

Although I could go on and on with dozens more examples of new features, space is limited in this magazine. So, get your hands on a copy of VFP 8 and dig right in. You'll soon be as excited as I am.

Claudio Lassala is a Senior Developer at EPS Software Corporation and a part time Universal Thread Consultant. He had presented several lectures at Microsoft Brazil and VFP conferences as well. He is a two-years recipient for the Microsoft MVP Award and also a columnist in MSDN Brazil. He is the author of several training videos for Visual FoxPro that can be found in the Universal Thread, inclusively a 40-minute video called "What's new in VFP 8," that shows off several enhancements of this new version. You can reach him at claudio@eps-software.com.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date