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!

Grid TextBox Property Changes 2

Status
Not open for further replies.

AllanB1

Programmer
Dec 30, 2002
201
US
I am trying to change the BackColor property of a textbox in a column using the TextBox GotFocus event. While the change occurs when the control gets focus, it reverts back to its original state when it loses focus. Why?

I need the column's textbox's properties to remain in their changed state for the life of the form. How?

Thank you.
 

Thanks Mike. I hadn't thought of that. But, unfortunately it is changing the BackColor of ALL textboxes in that column when the first textbox receives focus.
 
Hi Allan,

There is nothing native to VFP that would change the BackColor when the textbox loses focus. My first suspicion is that there is code in the LostFocus() event of the textbox, the column or one of their ancestors that does something. I would step through moving the focus off the textbox in the Debugger to see what I could see.

pamela
 

Pamela

To eliminate other causes, I created a new test form with a plain grid from scratch. There is no other code involved. When I place the following code in Column1's, Text1 SetFocus method, it changes color when the cell is selected, then reverts to the previous (if sparse is .T.) when it loses focus. I need the cell to stay the new color once it has been accessed until the form closes.

If sparse is .F. (as Mike Lewis suggested), ALL text boxes in column1 change color and stay changed. I also tried adding the NODEFAULT clause and DODEFAULT() to no avail.

Code:
THIS.BACKCOLOR = RGB(255,0,0)

Thanks.
 
If you want all cells (textbox) in a column to each have different colors there is a lot more involved. All textboxes in the coloumn are the same control using the same controlsource.
The following is to give you an idea on how to do it, but (IMO) not worth the effort.
One convoluted way is to create another hidden column. insert Values in it from 1 - 10 then repeat , Now with Icase() using Dynamicbackcolor - "Column" you can set the color for the first 10 then repeat for the next 10 and so on.
Depending on how many colors you want to code in your Icase() , thats how many colors you will have. Limit is 100.
I have Not tried it, It may or may not work. Try it and please repost.
 
Imaginecorp:

I do not want all cells to have different colors, just ONE different background color (or any other textbox property change, for that matter) once the individual cell has been accessed.

I did not think this was asking too much for VFP to do, and thought I was missing something very obvious.

I guess it is more difficult - or not possible - than I thought.

Thanks.
 
Sorry was not following you.
You probably could do it. Look up syntax for dynamicbackcolor in Help. You want to change the color to signify that changes were made to a field right?

I am pretty sure you can not do this with gotfocus().
But In the Dynamicbackcolor logic you could check for Oldval()
iif(nvl(oldval(...),"") <> nvl(curval(...),"")...

You will have to fool around with this...
 
Sorry, It just Cannot be done...I hope somebody will prove me wrong.
 
May be you can use Imaginecorp's idea and tip from Mike(sparse = .f.)

plus

1. Modify structure of your table and add a Logical field such as VISITED.

2. In the init() or load() of the form set VISITED to false (.f.) of this table. Such as
replace all VISITED with .f. (check time ???)

3. Then in your gotfocus() replace the VISITED with true(.t.)

4. Set your dynamicbackcolor according to the values in the VISITED field. Example:

thisform.grid1.Column3.DynamicBackColor = ;
"iif(VISITED,rgb(255,0,0),rgb(254,254,254))"

try it


Nasib Kalsi


 
This is how you do it.
its 14 after midnight and I had to try it...need a life...I am sure you all know the feeling...sad

Nasib Kalsi: you beat me to it though (damn)
Use Nasib's excellent example for Visits

Use the following for Changes.

Create a logical field in your table (lets call it checkfield). Depending on the columns you want to recolor you may have to create a few more
for this example, lets change only one column. In the textbox Valid() of the column put in:

select customer
if oldval(<<fieldname>>,"customer") <> this.value
replace checkfield with .t.
endif
oGrid = thisform.Grid1
nRec = 0
scan
if customer.checkfield
oGrid.column(3).dynamicbackcolor = "IIF(checkfield, RGB(255,0,0), RGB(255,255,255))"
nRec = Recno()
endif
endscan
if nrec > 0
goto nrec
endif

If you have vfp9 use a Select into cursor, so you dont have to change the structure of the table:
select company,cast(company as L) as checkfield ;
from customer into cursor DamnGrid readwrite
*enable buffering for oldval() to work
=cursorsetprop("buffering",5,"DamnGrid")
now use this cursor for the grid

Fine tune this and it should do what you want...
Good Night.

 
Refined version: Single column Grid. I used a table with 5001 records to check for speed. Nano Seconds for the scan
Also: Last Nights code had "Column(3)" should be "Columns(3)"

**Textbox.valid()
Select contmaster
nRecno = 0

If Nvl(Oldval("today","contmaster"),"") <> This.Value
Replace contmaster.tradein With .T.
nRecno = Recno()
Else
***dont want the scan to fire if value has not changed
Return
Endif
oGrid = Thisform.grid1
Scan
If contmaster.tradein
oGrid.columns(1).DynamicBackColor = "IIF(tradein, RGB(255,0,0), RGB(255,255,255))"
Endif
Endscan
If nRecno > 0
Goto nRecno
Endif

Fine tuning is required. Another possible use could be a simple Multi Select Grid etc, etc....


 
Thanks go to all of you for your efforts. I will try one of the ideas when I return to my office. Looks like the last 2 will both work. Hadn't thought of using the table to record cell access.
 
Imaginecorp: Thanks for your comments. I was not sure if that is what he needs, but thought I should give a try.
I am still in the learning stage and learn new constructs from everyone.

My Best

Nasib
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top