how to_ display controls in grid columns

2

Click here to load reader

Upload: ashtikarprabodh3313

Post on 12-May-2017

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: How To_ Display Controls in Grid Columns

0 out of 2 rated this helpful - Rate this topic

Tip

How to: Display Controls in Grid ColumnsVisual Studio 2005

In addition to displaying field data in a grid, you can have controls in the columns of a grid so that youcan present a user with embedded text boxes, check boxes, drop-down list boxes, spinners, and othercontrols. For example, if you have a logical field in a table, when you run the form, a user can tellwhich record values are true (.T.) and which record values are false (.F.) by seeing whether the checkbox is set. Changing the value is as easy as setting or clearing the check box.

You can add controls to grid columns interactively in the Form Designer or write code to add thecontrols to the columns at run time.

To interactively add controls to a grid column

Add a grid to a form.1.

In the Properties Window (Visual FoxPro), set the ColumnCount property of the grid to thenumber of desired columns.

For example, type 2 for a two-column grid.

2.

In the Properties window, select the parent column for the control from the Object box.

For example, select Column1 to add a control to Column1. The border of the grid changes toindicate that you are editing a contained object when you select the column.

3.

Select the desired control on the Form Controls toolbar and click in the parent column.

The new control will not be displayed in the grid column in the Form Designer, but it will bevisible at run time.

4.

In the Properties window, make sure the control is displayed indented under the parent columnin the Object box.

If the new control is a check box, set the Caption property of the check box to " " and the Sparseproperty of the column to false (.F.).

5.

Set the ControlSource property of the parent column to the desired table field.

For example, the ControlSource of the column in the following illustration is products.discontinufrom Testdata.dbc in the Visual FoxPro ...\Samples\Data directory.

6.

Set the CurrentControl property of the parent column to the new control.7.

When you run the form, the control is displayed in the grid column.

To remove controls from grid columns in the Form Designer

In the Object box of the Properties Window (Visual FoxPro), select the control.1.

Activate the Form Designer.

If the Properties window is visible, the control name is displayed in the Object box.

2.

If you want to be able to center a check box in a grid column, create a container class, add a checkbox to the container class, and adjust the position of the check box in the container class. Add thecontainer class to the grid column and set the ControlSource of the check box to the desired field.

How to: Display Controls in Grid Columns http://msdn.microsoft.com/en-us/library/2c84bwwk(v=vs.80).aspx

1 of 2 10/13/2012 12:17 AM

Page 2: How To_ Display Controls in Grid Columns

Note

Tip

Press the DELETE key.3.

You also can add controls to a grid column using the AddObject Method in code.

To programmatically add controls to a grid column

In the Init Event of the grid, use the AddObject Method to add the control to the grid column andset the CurrentControl Property of the column.

For example, the following lines of code in the Init event of a grid add two controls to a grid columnand specify one of them as the current control:

In this example, Column1 has three possible current control values:

spnQuantity

cboQuantity

Text1 (the default control)

THIS.grcColumn1.AddObject("spnQuantity", "SPINNER")THIS.grcColumn1.AddObject("cboQuantity", "COMBOBOX")THIS.grcColumn1.CurrentControl = "spnQuantity"* The following lines of code make sure the control is visible* and is diplayed in every row in the gridTHIS.grcColumn1.spnQuantity.Visible = .T.THIS.grcColumn1.Sparse = .F.

Properties set on the Grid level are not passed on to the columns or headers. In the sameway, you must set properties of the headers and contained controls directly; they do notinherit their properties from settings at the Column level.

For the best display of combo boxes in grid columns, set the following combo box properties:

BackStyle = 0 && TransparentMargin = 0SpecialEffect = 1 && PlainBorderStyle = 0 && None

How to: Display Controls in Grid Columns http://msdn.microsoft.com/en-us/library/2c84bwwk(v=vs.80).aspx

2 of 2 10/13/2012 12:17 AM