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!

Adding controls to variable size grids. 1

Status
Not open for further replies.

njpilot172

Programmer
Aug 9, 2005
10
US
I'm 1 step away from completing my attendance program.
I am trying to figure out a way to add a checkbox to all but the first column in a grid that has a columncount of -1.

I need to do this because I do not know how many columns the grid will contain (length of program in days) until the underlying queries are actually run.

I'm thinking of doing something like:
lnColCount = .ColumnCount
FOR lnKnt = 2 TO lnColCount
.column(lnknt).AddObject("chk1","checkbox")
.column(lnKnt).currentcontrol = "chk1"
.column(lnKnt).sparse = .F.
ENDFOR

Of course you can't reference ".column(lnKnt)" in real life.
This is the part I'm trying to figure out.

My other option is to manually create a grid with 254 columns of checkboxes and remove the columns that I do not need (YUCK!!!).

Any help would be appreciated (I ended up being the only reply to my first post).

Todd
 
You can set the columncount of the grid at runtime. This will give you the columns you need, then just add the checkboxes and set them as the current control as you are doing. You can also remove the default control Text1 from the columns by using removeobject method just like you are using addobject method.

boyd.gif

SweetPotato Software Website
My Blog
 
Thanks Craig,
I actually hit upon that during my testing.
Here is my code right now. I'm using macro substitution to create the fields and the checkboxes. My only hang-up now is getting the checkboxes to attach to the underlying logical fields.

------------------------
lnColCount = .ColumnCount
FOR lnKnt = 2 TO lnColCount
lcTargetField = FIELD(lnKnt)
lcHeader = SUBSTR(lcTargetField,2,LEN(lcTargetField))
lcHeader = STRTRAN(lcHeader,"_","/")

lcGrdCmd1 = ".column"+ALLTRIM(STR(lnknt))+".header1.Caption='"+lcHeader+"'"
lcCmd1 = ".column"+ALLTRIM(STR(lnknt))+".AddObject('chk1','checkbox')"
lcCmd2 = ".column"+ALLTRIM(STR(lnknt))+".currentcontrol = 'chk1'"
lcCmd3 = ".column"+ALLTRIM(STR(lnknt))+".chk1.caption = ''"
lcCmd4 = ".column"+ALLTRIM(STR(lnknt))+".chk1.controlsource = curattn."+lcTargetfield
lcCmdx = ".column"+ALLTRIM(STR(lnknt))+".sparse = .F."

&lcGrdCmd1
&lcCmd1
&lcCmd2
&lcCmd3
&lcCmd4
&lcCmdx
ENDFOR

------------------------

I can change the values of the fields from .F. to .T. using the textbox, but can not do the same using the checkboxes.

My final hurdle.

I see the light at the end of the tunnel (or is that an approaching train....)

Todd
 
Craig,

THANK YOU THANK YOU THANK YOU.

I found my answer in a post that you sent to LordHawkins on 06/01/2005. Our code (your sample and mine) were nearly identical. I was, however, missing the Check1.visible = .T..
I didn't even think of it because I could see the checkbox right there (sparse = off).

It is now working properly and time to dump the data somewhere for easy retrieval.

T
 
Hi Todd,

I thought that this format:

.column(lnknt).AddObject("chk1","checkbox")
.column(lnKnt).currentcontrol = "chk1"
.column(lnKnt).sparse = .F.

Only worked within a WITH - ENDWITH structure.

Regards,

Mike
 
Mike,

Sorry, if I confused anyone.

Actually the .Column(lnKnt)... does exist within a With...Endwith structure.

If you notice, I was also using macro substitution in my reply to Craig's post. I could not do .Column(lnKnt) directly.

The grid is now up and running perfectly.

Todd
 
Just as an aside, while your way will work fine you could change your WITH statement a little and shorten things up:
Code:
lnColCount = .ColumnCount
FOR lnKnt = 2 TO lnColCount
  lcTargetField = FIELD(lnKnt)
  lcHeader = SUBSTR(lcTargetField,2,LEN(lcTargetField))
  lcHeader = STRTRAN(lcHeader,"_","/")

  STORE ".column"+ALLTRIM(STR(lnknt)) TO cColVar
  [COLOR=blue]WITH ThisForm.Grid1.&cColVar.[/color]
     .header1.Caption = lcHeader
     .AddObject('chk1','checkbox')
     .currentcontrol = 'chk1'
     .chk1.controlsource = curattn."+lcTargetfield
     .sparse = .F.
  ENDWITH
ENDFOR
There may some typographical errors here, but your get the drift.

-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top