Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grid data 1

Status
Not open for further replies.

foxup

Programmer
Dec 14, 2010
328
CA
Hi All,

I have a grid for which a field is being displayed. The field is controlsource=dslorder.intercon

this field is a numeric but what I would like is that in the grid if the value of dslorder.intercon=0, put "No" in the grid column. If the value of dslorder.intercon=1, put "Yes" in the grid value.

please help.


Thanks,
FOXUP!
 
Why not checkbox?

Borislav Borissov
VFP9 SP2, SQL Server 2000,2005 & 2008.
 
You mean checkbox in my grid? I guess so. I just thought it would be easier the other way. can you help with the checkbox then?

 
Lacking familiarity with the tools, this can get tricky. It's probably easiest to use the builder.

Right click the grid and choose "Builder". On the "Layout" tab, select the column in question and change the "Control Type" to checkbox.
 
While the results might end up being the same I use a somewhat different approach to putting a checkbox into a Grid.

A Grid will 'inherit' Textboxes for each Column when it is created. You want to add a Checkbox to the desired Column and then Delete the original Textbox.

* Open the Form in the Form Designer
* Have the Form Controls Toolbar visible on-screen
* In the Form Properties window, select the Grid's individual desired Column
* Go to the Control Tools and pick the Checkbox
* Move the cursor to the individual desired Column and click

That will put a Checkbox object into the individually selected Column within the Grid.

* Now within the the Form Properties window, select the Grid's individual desired Column Textbox.
* Move the cursor back to the Grid on the Form
* Hit the Delete key and that should remove the original Textbox from the Grid's Column leaving the Checkbox object
* Change the Grid Column Checkbox properties as needed to display your Logical values.

One other issue: For the desired Grid Column you will have to set property grid.column.sparse=.f.

NOTE - if my 'explanation' is too confusing you might also look at:
thread184-887233
thread184-768151 <- Mike Gagnon describes how to add a ComboBox instead of a Checkbox, but it is the same process.
thread184-548792

Good Luck,
JRB-Bldr
 
Hang on a moment, Foxup. Are you sure you want a checkbox in the grid?

If you want the user to be able to change the value (from Yes to No or vice versa), then a checkbox is a good choice. But if you just want to display the information, then it would be better to stick with the textbox..

If that's the case, you can do this:

1. In the form designer, right-click on the grid and choose Edit. Then click on the column that will contain the Yes or No. (Check that the column is selected by looking at the drop-down list at the top of the property window.)

2. Drop a textbox into the column (either from the form controls toolbar, or the project, or the toolbox, or whatever you normally use).

3. In the property window, you should now see two textboxes within the column. Give them meaningful names, such as txtYes and txtNo.

4. Set the Value property of the textboxes to Yes and No respectively. Also, set their ReadOnly to .T. Don't worry about the ControlSource.

5. In the Init of the grid, add this code:

Code:
THIS.Column1.DynamicCurrentControl = ;
  IIF(dslorder.intercon=0, "txtNo", "txtYes")

(Change Column1 to whichever column holds the textboxes.)

6. You might also need to set the grid's Sparse property to .F.

When you run the form, you should see the Yes and No in each of the rows in the relevant column. If the value in dslorder.intercon changes, you need to refresh the grid in order for the change to take effect.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Hi Mike,

You know exactly what I want to do. :)

I tried your consult and it gives me an error:
"Expresion is invalid. Use a valid expression for dynamiccurrent control property".

Any help?

Thanks,
FOXUP!
 
Oh, i found the mistake! Thanks Mike. Star for U. :)
 
My fault. Instead of this:

Code:
THIS.Column1.DynamicCurrentControl = ;
  IIF(dslorder.intercon=0, "txtNo", "txtYes")

Do this:

Code:
THIS.Column1.DynamicCurrentControl = ;
  [b][[/b]IIF(dslorder.intercon=0, "txtNo", "txtYes")[b]][/b]

In other words, delimit the stuff after the "=" with square brackets (or single quotes if you prefer).

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top