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!

Change Caption on CommandBox in Grid 1

Status
Not open for further replies.

foxup

Programmer
Dec 14, 2010
328
CA
Hi,

I have a simple question. How do I change the Caption or the color of the Caption Font in a Grid according to the value in the field. Example: Field is empty, change color or caption to "None" you know what I mean?

The IIF doesn't seem to work in there for some reason.

What am I missing? I'm pretty sure it's easy but I'm just not thinking inside the box.

Any help please.


Thanks,
FOXUP!
 
There is no Caption on a Grid.
What do you mean?

There are individual Column Headers. Is that what you mean?

Field is empty, change color
You can change the ForeColor or BackColor of individual Column textboxes based on an expression using the DynamicForeColor and DynamicBackColor expressions

Put something like the following into the DynamicBackColor expression: IIF(EMPTY(ThisField),RGB(255,255,0),RGB(255,255,255))

Good Luck,
JRB-Bldr

 
caption on the command button in a grid, sorry. forgot that part. :)
 
command button in a grid

Again, unless you have added one or more new buttons to one or more columns of your Grid, there are no Command Buttons in a Grid.
Grid
Column1
Header1
Textbox1
Column2
Header2
Textbox2
etc....

So I am still not clear on what you are describing.

Command Buttons can be added to a Form separately from the Grid and they can, through their own methods and properties, be controlled and can be used to control a Grid.

Good Luck,
JRB-Bldr

 
I added one new button to one columns of my Grid. How do I change the Caption of hte button or the color of the Caption Font of the button in a Grid according to the value in the field.


Example: Field is empty, change color or caption to "None" you know what I mean?


Thanks,
FOXUP!
 
Try something like the following:

IF EMPTY(GridDBF.ChkFld)
ThisForm.Grid1.Column2.Button1.Caption = "EMPTY"
ThisForm.Grid1.Column2.Button1.ForeColor = RGB(255,255,0)
ThisForm.Grid1.Column2.Button1.BackColor = RGB(32,230,55)
ELSE
ThisForm.Grid1.Column2.Button1.Caption = " "
ThisForm.Grid1.Column2.Button1.ForeColor = RGB(255,255,255)
ThisForm.Grid1.Column2.Button1.BackColor = RGB(255,255,255)
ENDIF

Good Luck,
JRB-Bldr
 
If you are really asking about command button, you can set the FontColor *BUT* (and this is a big but), it isn't dynamic. It won't be evaluated row-by-row. It will only be evaluated once for the entire grid.
 
Doesn't seem to work quite right. I added that to the Command1.Init and doesn't work. Any other ideas?

Thanks,
FOXUP!
 
I would need it to be be evaluated row-by-row for sure. How can it be done?
 
Actually, as I mentioned in my 1st post. It doesn't really need to be the Font Color, it could be the Caption, it could be 'enabled/disabled'. Anything really to differentiate the 'state' of the field behind the command box.

Thanks in advance,
FOXUP!
 
Only the Value of controls is bound to a grid recordsouce. Captions are static.

So changing a button caption row by row needs to go through some of the Dynamic-Properties, calling a method, which then changes the button caption.

Bye, Olaf.
 
need it to be be evaluated row-by-row for sure

Does it need to be applied as the user moves through the Grid row-by-row?

If row-by-row then put the code into the Grid1.AfterRowColChange method

NOTE - those RGB() color sets I used were not the ones you will need. Determine and use the color sets that match your needs for both the EMPTY() condition and the !EMPTY() condition.

Or all-at-once for all records?

If that were to be the case then you would need to handle it differently.

Good Luck,
JRB-Bldr


 
OK, I misunderstood row-by-row. It does not need to be applied as the user moves through the Grid row-by-row. It just needs to be applied once upon the grid load. As you said jrbbldr, it only needs to be applied all-at-once for all records.

I tried the code jrbbldr wrote and it doesn't work. I added that to the Command1.Init and doesn't work. Any other ideas?

Thanks,
FOXUP!
 
AfterRowColChange is happening row by row, but only in the moments you change from one record to another by clicking into a different row or using up/downarrow. Not when the grid is drawn.

Only the Dynamic... properies are evaluated for each row drawn while they are drawn and offer the possibility to change something to be different on any row.

Bye, Olaf.
 
OK, so I assume it would be dynamic property that would needed to be looked at but that changes the whole row right?

I just want to change the command box caption/font in the grid as per the contents of the field.

Thanks,
FOXUP!
 
OK, so I assume it would be dynamic property that would needed to be looked at but that changes the whole row right?

Absolutely not. The only thing that operates on an entire row is .RowHeight and the delete mark.

There is NO row object in a grid. Grids are composed of columns and the contents of those columns.

I just want to change the command box caption/font in the grid as per the contents of the field.

There is no control named command box. I assume you still mean command button.

The control you are using was not built to do what you are trying to do. You are barking up the wrong tree.
 
Second thoughts: you can kludge this into place.

Use *TWO* command buttons in the column, one with the "normal" color/caption, the other with the "NONE" color/caption. Use the .DynamicCurrentControl property to make the right control visible depending on the field's content.
 
Ah, yes, that works danfreeman. Thank You.
 
Actually Olaf, I followed your advise and did it the simple way. All I did was put:

thisform.grid1.column32.DynamicForeColor = "IIF(EMPTY(dbfname.fieldname),RGB(0,0,0),rgb(0,100,0))"

in the init of the form which holds the grid and it works like a charm.


Thank You,
FOXUP!
 
Instead of just setting the color, at that point you can call a method and everything else you want in there, eg change the commandbutton caption.

thisform.grid1.column32.DynamicForeColor = "thisform.column32dynamiccolor()"

Add a user defined method "column32dynamiccolor" to the form and in it do whatever you like, that's what I said.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top