Adding a checkbox to a Foxpro grid

A column in a grid can hold any other control - even a large and complex container such as a pageframe or another grid. A simple example is to replace the textbox with a checkbox as shown in the example below:

[Add a control to a grid]

The technique to replace the textbox with another control is simple, but not obvious. The problem is that you seem to have no way of selecting the textbox on screen so that you can delete it. The trick is to use the Properties Window to make that selection:

  • Right-click on the grid.
  • Select Edit to allow selections within the grid.
  • Click on the checkbox in the Form Controls toolbox - see the note in the next paragraph.
  • Click on the column in the grid.
  • Nothing will change on screen - the column will still appear to hold a textbox.
  • Go to the Properties Window and look at that column.
  • You should see that the column holds two controls.
  • Click on the textbox to select it.
  • Now click on the form - click on the header of the form rather than on any control within the form. You have very carefully selected the textbox in the column and you do not want to change that selection by clicking on the body of the form or on any control within the form.
  • Press the Delete key.
  • The textbox should disappear to show the checkbox that has been hiding behind it.

Adding a control from a custom library

When you are adding controls to a form you have the alternatives of clicking on the Form Controls toolbar or dragging a control from a class library on the Classes tab of the Project Manager. This second option does not work when you are trying to add a control to a grid. Use the technique described here to show the custom controls on the toolbar.

Aligning the checkbox

By default the chackbox will appear against the left-hand edge of the column. This is usually wrong. The grid in VFP 9 has a new property which lets you set the alignment of the control in the column. In earlier versions the workaround is to centre the checkbox manually inside a container and then add the container to the column. The container itself will be left-justified but if the container is made transparent and borderless then the checkbox will appear to be centred.

Highlighting the selected rows

In this example the customer wanted a really clear way of seeing which entries had been selected. The grid's DynamicForeColor property allowed me to grey out those rows which were not selected.

Back to FoxPro Developers' page


Hints & tips

The textbox class in Visual FoxPro 9 has a new Autocomplete property which shows the user the previous values that have been entered in that textbox.
Autocomplete in VFP 9

Your Access database will look more impressive if you add custom toolbars...
Custom toolbars

FoxPro has always had functions to read and write files at a low level...
Foxpro low level file functions

More...
More pages of hints and tips for users of Microsoft FoxPro and Access databases.

Site Map