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

Change the Caption of Checkbox within Grid

Status
Not open for further replies.

JRB-Bldr

Programmer
May 17, 2001
3,281
US
I am wondering if there is a way to change the Caption of a Checkbox within a Column on a Grid.

What I want to display is the value of one of the record's fields which generally changes per record.

Your advice and/or suggestions would be most welcome.

Thanks,
JRB-Bldr
 

Depends on how many distinct values there are for the field in question.

If the field is open-ended, that is, it can contain many values and you don't know in advance what those values are, then there's no obvious way of doing it with a checkbox. You might have to use two separate controls: a checkbox without a caption, and a separate read-only border-less textbox to simulate the caption.

If, on the other hand, you've got a relatively small fixed number of possible captions, you could create a separate checkbox object for each of them (hard-code the captions, in other words), then use the DynamicCurrentControl property to select the one you want for a given row.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike - thanks for the quick reply.

Unless I have no other choice, that is probably a somewhat more complex approach than this issue deserves.

Perhaps someone else has some other ideas.

Thanks,
JRB-Bldr
 
Mike,

Not tested, but wouldn't something like the following work?
Code:
* In the AfterRowColumnChange event call this method
This.column1.chkBox.Caption = This.column2.text1.Value
Of course that would reset the captions of all the checkboxes which might be time consuming and not the effect he's after.

Regards,
Jim
 
Jim,

I had a similar idea,
ThisForm.Grid1.Column1.Checkbox.Caption = MyTable.Field3

But when I tried putting this into my Grid's AfterRowColChange method (and your suggestion as well), I got ALL row checkbox captions being set to the same single value instead of each row displaying its own record's field value.

Thanks,
JRB-Bldr
 

In order to affect the rows one at a time, you need to put the code in the init of the grid, which will evalute to caption one row at a time. And if something changes make a call to the init again.
Code:
 with this
  .Column1.Checkbox.Caption = MyTable.Field3
Endwith




Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Mike - I thank you for your reply

NOTE - the Field3 values does not change during a single user session, so an individual record's value is a constant throughout the session.

I tried putting your suggested code into the Grid1.Init method and when the Form displayed the Grid, I got the same results as before.

With a table whose Field3 value changes from record to record, I still got Record #1's value in ALL of my checkbox captions.

In fact I also tried a modification to your code
Code:
SELECT MyTable
SCAN
  WITH THIS
     .Column1.CheckBox.Caption = MyTable.Field3
  ENDWITH
ENDSCAN
GO TOP
And merely ended up with a different last record's Field3 value in ALL of the CheckBox captions.

What I am wanting to get is each separate record's individual Field3 value in its own record's checkbox caption.

One additional note -- It is obvious to me so I didn't think to mention it before, but for the sake of clarification -- the Field3 value which I want to use for the Caption is Text and that the CheckBox ControlSource is a different field value which is Logical.

Thanks,
JRB-Bldr
 
JRB-Bldr,

I'm pretty certain that any solution that involves actually changing the checkbox's caption will not work. That's because there is really only one checkbox and one caption on display at any one time. It just looks like there is a whole grid-full of them.

It's precisely for that reason that VFP has all the DynamicXXX properties. What you really need is a DynamicCaption property, but that doesn't exist.

I think your best bet would be to split the column in question into two columns: one containing a checkbox without a caption, and one containing a text box that's ControlSource'd to the field in question. With a bit of fiddling, you should be able to make the text box look like a caption.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike - Thanks for the suggestion.

In light of the amount of attention other issues/priorities need, I'll just need to evaluate how much effort this issue deserves, but your suggestion does sound workable.

Thanks,
JRB-Bldr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top