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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying a check (Tick) in a grid

Status
Not open for further replies.

AndrewMozley

Programmer
Oct 15, 2005
623
GB
I have an application which displays a grid of the outstanding and historic invoices for a particular customer. Two of the columns show the original invoice value and the amount paid against that invoice.

I plan to leave the second column blank if the invoice is unpaid, and to show the value of the part-payment if the invoice has been partly paid. If the invoice has been fully paid I would rather like to put a "Tick" or check-mark.

Is there a way of doing this? At present the record-source of the grid is a cursor which is populated by reading the sales ledger. The font for the grid is Arial.

Thank you
 
Andrew,

Yes, this is quite easy. First, you need to add a checkbox to the column in question. Having done that, you need to remove the text box from that column (or, alternatively, set the checkbox to the be the active control). Set the checkbox's Control Source to a logical field that says whether you want to show the tick (add that field to the underlying cursor if not already present). The checkbox will then show the tick as required.

You might also want to set the column's Sparse property to .F., to make the checkbox visible in every row. And also set the column to ReadOnly.

Come back if you need more details.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks Mike.

I have attempted this. However if I remove the text box, then I am not able to display the "part-payment" value; I want to do this if an invoice has not been fully paid; otherwise I want to display the check box with a tick.

Am I going to have to have a separate column for the check box; I had rather hoped to put it in the same column as the part value.

Andrew
 
No, you can have both, but use the DynamicCurrentControl to switch between them

The code might look a bit like this:
Code:
THISFORM.GRID1.COLUMN3.DYNAMICCURRENTCONTROL="IIF(MYTABLE.FULLYINVOICED,'Check1','Text1')"

But to do this you need to NOT delete the text box, just add the check box (and remove its caption)

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
Andrew,

It would have to be a separate column. Off-hand, I can't think of any way that you could put the amount and the tick in the same column.

Oh, hang on. It might be possible. You could create a container class, which would hold the checkbox and a texbox side by side. You could then place the container in the column. But it would be quite complicated. Off-hand, I can't think of any easy way of binding the container to the underlying field. It might be worth pursuing if you really want to, but having a separate column would be much easier.

Another possibility: rather than showing a tick, how about highlighting a fully-paid invoice in some other way, such as showing it a different colour (or, show paid invoices in the default colour, and show unpaid in, say, red - or bold, or italic, or something). This would be much easier, because you wouldn't need a new column, and you wouldn't need a new field in the cursor.

If you are unsure how to do any of this, these two pages might be of some help:

Understanding the Visual FoxPro grid control
Conditional formatting in a Visual FoxPro grid

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Griff's reply crossed with mine. His suggestion of using DynamicCurrentControl would work, but only if you want to show the payment amount instead of the checkbox. I was assuming you wanted to show them both at the same time.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike you could surely do it with an image and a text control, binding the column to the
field and then using the dynamiccurrentcontrol to show an image of a tick?

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
sorry crossed postings again

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
Thank you all, particularly GriffMG for pointing out that you can include code which chooses whether to display a text box or a check box.

I am still trying to display a check box (at all) in the column. Going back to first principles, I am trying always to display a check box.

I have included this code, which certainly executes before the grid is displayed.

SELECT cEntries
GO TOP
.grdResult.recordSource = "cEntries"

.grdresult.Column6.DYNAMICCURRENTCONTROL = "'Check1'"
.grdResult.refresh()
.grdResult.visible = .T.

There is a check box, 'Check1' a property of Column6 (which I have set to have a default value of 1, for testing). However the column displays as a blank.

The DYNAMICCOMMONCONTROL command is obviously having some effect, because if I do not include it, I get the value of the default text box.

As always
 
sparse = .f.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
You need to have at least 1 record for something to show up, besides sparse=.f.

Also DYNAMICcurrentcontrol only makes sense, if you'd have an expression there, which is one control name in some cases and another controlname in another case, eg some IIF() or ICASE().
As you reverted to using a separate column for the checkbox, you only need to set CURRENTCONTROL. It doen't hurt, if DYNAMICCURRENTCONTROL is set to "Check1", but it doesn't make this dynamic in any way.

And as a last explanation: The checkbox has a label, but like the normal label it can't be bound to a text field, the caption property is not the value/controlsource combination of data bindable controls. You can only bind the checkbox part of the checkbox to data and the label would just be a caption you can already set in the grid header, so in a grid the checkbox label would be very redundant and you normally won't set it at all.

Bye, Olaf.


 
OK, I can see now why you would want to display the tick instead of the amount when the invoice is fully paid. Thanks to Griff for clarifying that.

If you are having problems with a checkbox, an easy alternative would be to place a label in the column (rather than the checkbox). Set its font to Wingdings, and set its caption to CHR(254). Use DynamicCurrentControl to select the label when the invoice is unpaid, otherwise the default text box.

You will probably still need to set Sparse to .f. to make it visible in every row.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Sparse = .F. does the trick, Mike and GriffMG. Strange how I need to be told twice!

Grateful for this guidance, The default option for Sparse seems to cause DYNAMICCURRENT CONTROL to be ineffective.

I am using the check box , but would still like to consider the option of using an image - mainly to remove the border on the "tick". Is there a black-and white image for a "tick" readily available?

Will there be any problem about making the image file available when I distribute the application? I am using the project manager to build the .exe file and InstallShield Express to distribute.

Also, when the form is re-sized, the form re-sizes the grid and the grid re-sizes its columns and fonts. Will it be possible to re-size the image.

Andrew M.
 
DYNAMICCURRENTCONTROL and SPARSE operate independant of each other. The only difference is, if sparse is set .t. all rows will have the right control and not just the active one.

As you set DYNAMICCURRENTCONTROL = "Check1", all rows will have check1. I already said it only makes sense to set DYNAMICCURRENTCONTROL to an expression, which results in different control names on different conditions.

Bye, Olaf.
 
I am using the check box , but would still like to consider the option of using an image - mainly to remove the border on the "tick". Is there a black-and white image for a "tick" readily available?

Yes. In the VFP9 directory, drill down to Graphics\Icons\Misc. You will find a file named CHECKMRK.ICO.

Will there be any problem about making the image file available when I distribute the application?

No. Just add the file to your project, and make sure it is not flagged as excluded. It will then be bound into the executable, and will be available at run time.

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thank you Mike. Found that, and it works. Small point, how can I remove an extra property (the check box, "check1" which I had placed on my Column 6). I had placed it on the column by dragging and dropping from the form controls toolbar, but since I cannot see it visually at design-time, I do not know how to remove it.

Resizing. It may however be a bridge too far to use an icon in a cell in a grid; I re-size text boxes and labels in a column when the grid is re-sized - by changing the font size - and that works pretty well. It is probably too optimistic to hope that there is a similar "one touch" method of re-sizing an icon ?

 
Hi

Get the form up. right click on the grid, select edit.

In your properties window, use the drop down at the top to find your checkbox
then click in the column on the grid and hit your delete key

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
.... "one touch" method of re-sizing an icon

Just set the Image control's Stretch property to 1 (isometric).

Alternatively, see my earlier post about using the Wingdings font instead of an image. That way, you would be able to work with the familiar Fontsize property.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Sorry, I might have missed something. You said:

I re-size text boxes and labels in a column when the grid is re-sized

What I said about setting the Stretch property is still true. But if you want the image to resize automatically when the grid is resized, you will also have to set its Anchor property. Setting it to 15 should give you the desired result.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top