Microsoft KB Archive/129280

From BetaArchive Wiki
Knowledge Base


Article ID: 129280

Article Last Modified on 6/29/2004



APPLIES TO

  • Microsoft Visual FoxPro 3.0 Standard Edition
  • Microsoft Visual FoxPro 5.0 Standard Edition
  • Microsoft Visual FoxPro 6.0 Professional Edition



This article was previously published under Q129280

SUMMARY

The Grid control is more flexible than the BROWSE command. A Grid contains columns that in turn contain controls, it is possible to manipulate data at the control, or cell, level. The example provided in this article shows how to modify the color of an active cell when you access it with the keyboard or the mouse.

MORE INFORMATION

You can add any control to the column of a grid, and can access its properties, events, and methods. The ACTIVECONTROL property returns the name of the control displayed in a column, and by default, a column of a grid contains a text box with the name Text1.

Step-by-Step Example

This example provides a generic way to control the background color of the active control for any column in the Grid by using the Form Designer. It changes the value of the BACKCOLOR and SELECTEDBACKCOLOR properties.:

  1. Create a Form.
  2. Right-click the form, and select Data Environment. Select the SAMPLES\DATA\CUSTOMER table.
  3. Place a Grid on the form. In the property sheet, select Grid1 from the Object dropdown. Select the Init event handler, and type the following code:

       nColumncount=this.columncount
       * The color of the current control is changed to red for every column
       * in the grid.
       FOR I=1 to nColumnCount
          * Objref  returns a reference to the current control
          objref=EVAL('this.columns(i).'+this.column1.currentcontrol)
          * Modifies the backcolor property of the control. Any property of
          * the control can be manipulated this way.
          objref.BackColor=RGB(255,0,0)
          objref.SelectedBackcolor=RGB(255,0,0)
       ENDFOR
                                
  4. Save and run the form. When you access any cell on the grid, the background color changes to red.

This example will need a special case if the current control is a command button because the COMMANDBUTTON class does not have a BACKCOLOR or SELECTEDBACKCOLOR property.


Additional query words: VFoxWin

Keywords: kbhowto kbcode KB129280