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

Grid Text Box - Background Color Change

Status
Not open for further replies.

IForgot

Programmer
Mar 20, 2002
122
US
I am needing "beginner-level" help.

Admittedly the following is long-winded, but maybe if I give enough background info, it can help you assist me better.

I want to change the grid Column1 background color for the selected row ONLY when a value in one of the other columns is changed.
I have added a Valid method to the Text1 box for each changable column (Col 2, 3, 4, etc.) in the grid.

In these Valid methods I successfully check to see if the value is changed. If changed - I want to change the Col #1 background color. If not changed - return the background color to White.

I have read previous postings and I have also read
FAQ184-624 How can I color code cells in a grid?

But I still cannot get things to work.

Background:
* I use a PRG file to launch the application.
Within the PRG I isssue
DO FORM masschng

* Within the form I call my Valid methods by
RETURN ChkChng()

* The ChkChng function is in the PRG file.

* The parent of the specific Grid Text boxes are like:
frsMassChng.gcBrwsWind.PageFrame1.Page1.grdInventory.Column2

But when I reference that from Valid function in the PRG file, it tells me that it does not recognize one or more of the elements (such as frsMassChng or gcBrwsWind, etc.).

And when I attempt to put it directly into the FORM's Valid method, it blows up.

Your assistance would be greatly appreciated.

Thanks,
I_Forgot
 
Create a method of the formset called ChkChng. Everything will be accessible from there, use This.gcBrwsWind.pageframe1.page1.grdInventory.column2 from within the Formset (as an example). to add a method to the formset: when you have the formset up in design mode go to the system menu Form - New Method - and then add your code into the newly created method.

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
Here's what I encountered...

I did as suggested and added a new method named ChkChng to the Form.

Within the s I had:
RETURN ChkChng()

On execution the error message indicated no ChkChng.PRG could be found.

So....

As an alternative I put the entire function within the individual Grid Text Box Valid method and no longer used the above code.

Now, on execution I get the error message:
gcBrwsWind not found (or unknown)

This is what I meant originally when I said that it "blew up" when put directly into the Form's Valid method.

The code:
gcBrwsWind.pageframe1.page1.grdInventory.column2
came directly out of the form's database (.scx file) Parent field for that particular Text field, so I know that it is accurate.

Consequently, my confusion continues as to how/where to place the code. And what is the correct syntax to get things working.

Your advice and suggestions will be greatly appreciated.

Thanks,
I_Forgot
 
Create a method of the formset called ChkChng

My suggestion was not to call the ChkChng() function from the formset's method.

DO NOT call the function chkChng() from the formset's method. RATHER create a method of the formset called chkChng() and call "Return thisformset.chkchng()" from the valid event of the textbox in your grid. ALSO, check to make sure that the form you have in your formset really is named "gcBrwsWind", better yet refer to it like Thisform.pageframe1.page1.grdInventory.column2, however the example I gave you in my previous post will work if the method is created in the formset and the name of the form is really "gcBrwsWind".

If the above does not work then kindly post the name property for the formset and the form and also the code contained in the chkChng method and we will take this further.

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
Through trial and error and with much "flailing around", I have made a little progress, but not quite as intended.

I have abandoned the ChnChng() approach entirely. It might be the BEST approach, but the confusion factor is too great at this point.

However.....

By putting:
This.BackColor = IIF(tmp_invt.changed, RGB(255,255,0), RGB(255,255,255))
into the to-be-changed Text box's GotFocus method, I can get the cell color to change.

Unfortunately, not as desired, and not retaining its new color.

When I click the mouse into the cell it turns Yellow.

However in spite of the IIF() condition it changes color regardless of the value of tmp_invt.changed (default is FALSE). Then on moving the cursor to another record, the Yellow reverts back to White.

Dynamic color change - Yes
Behaving as needed - No.

I have given up with attempting to change the Col #1 (not-changed) text box color. I now will be content with changing the text box color of the specific text box where the value was changed - it works just as well visually.

But I still need:
1. To get the color change to "stick" to the specific changed cell even when I move to another record.

2. To get the change to work off of the value which is toggled in another field such as:
When value of tmp_invt.Type is changed then tmp_invt.Changed, it toggled from FALSE to TRUE.
If a record's tmp_invt.Changed = TRUE set background color Yellow - and make it 'stick' even when cursor goes to different record.

Maybe that has simplified things (or not). I can't tell for sure. But with this new approach perhaps someone has good advice on how to make it work as needed.

Your advice is greatly appreciated.

Thanks,
I_Forgot
 
Any additional suggestions on how to get the Grid Column's Text box backcolor to "stick" with the changed value?

Thanks,
I_Forgot
 
Try this.

Create a method... we can call ChangeColor with this simple code :

LPARAMETERS icFieldsState
RETURN IIF(AT('2', icFieldsState) > 0, RGB(255,0,0), RGB(0,255,0))

In the DynamicBackColor of the column you want to modify call this method.. so :

THISFORM.ChangeColor(GETFLDSTATE(-1,'customer'))

where 'customer' is your table name. You call the method passing the state of each field of the current table row (see VFP doc for GETFLDSTATE).

This example put the background green for the no-modified rows and red for modified ones. The only problem is that if you make a modification and the you step back VFP gives you the info that the field was however modified : i.e. the original content was 'Marco', you modify it to 'Marco1' and then you erase '1'.. the row is considered as modified... but you can change the code in the method properly to better fit your needs but remember you should pass from the calling instructions all the values you have to check, avoid referring the fields directly in the method...

Let me know if it works.
Ciao.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top