Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Grid - Showing Selected Record in Differenct Color
Message
From
14/07/1999 06:14:44
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00239661
Message ID:
00241167
Views:
14
Chuck,
It does work. For highlighting (aligning, bolding etc) current record create a custom property nCurRec in your grid class and :
* Grid.init
this.SetAll("DynamicBackColor", ;
      "IIF(RecNo(This.RecordSource) = this.nCurRec, "+;
      "RGB(0,0,255),RGB(255,255,0))", "Column")
* Grid.AfterRowColChange
this.nCurrec = recno(this.recordsource)

* That's all :) It Doesn't need a refresh when you're in grid
* For moving outside of grid (ie: a commandbutton skips in grid.recordsource
thisform.myGrid
  .nCurrec = recno(.RecordSource)
  .Refresh
endwith

* Another sample
* Changing colors for newly appended records in buffered mode
* Appended records have negative recno till updated ;)
* Grid.Init
WITH this
  IF !empty(.RecordSource)
    .SetAll("DynamicBackColor", ;
      "IIF(RecNo(This.RecordSource) < 0,RGB(0,0,255),RGB(255,255,0))", "Column")
    .SetAll("DynamicForeColor", ;
      "IIF(RecNo(This.RecordSource) < 0,RGB(255,255,255),RGB(0,0,0))", "Column")
  ENDIF
ENDWITH
In fact this doesn't need to be in grid.init. It could be in any method, event. Even you could use this in a timer event to make a flashing effect. Since grid does the evaluation for visible part (Cool:) calling this in a timer event doesn't cause a noticable performance degrade.
Why doesn't work then ? Well to my experience it's the wrongly written expressions. Just put (or forget) a parentheses in the expression and it wouldn't work nor give an error. Validate your expression in command window supplying dummy values if necessary first (I generally forget last closing parentheses in iif()).
PS: Pls note that for dynamic* series using "this" refers to grid itself not column. This is another pitfall I have been caught time to time.
Cetin

>Barbara,
>Thanks for your reply. I tried it with a form property named nRecNo, as follows...
>
>
>ThisForm.nRecNo = RECNO()
>ThisForm.Grid1.SetAll("DynamicBackColor", ;
>     "IIF(RECNO()=This.nRecNo), RGB(255,255,147), RGB(240,240,240))", "Column")
>
>
>But it didn't work. I also tried declaring PUBLIC mSelectedRecord, then using my code I tried before...
>
>
>STORE RECNO() TO mSelectedRecord
>ThisForm.Grid1.SetAll("DynamicBackColor", ;
>     "IIF(RECNO()=mSelectedRecord), RGB(255,255,147), RGB(240,240,240))", "Column")
>
>
>But, alas, that didn't work either. I've been on an "expedition" trying several other things but all to no avail. It seems that I'm just missing some little detail somewhere. I just don't understand why the simple example in help works, but my code doesn't. Again, the help example is...
>
>
>ThisForm.Grid1.SetAll("DynamicBackColor", ;
>    "IIF(MOD(RECNO( ), 2)=0, RGB(255,255,255) ;
>    , RGB(0,255,0))", "Column")  && Alternate white and green records
>
>
>Any help is greatly appreciated. TIA, Chuck
>
>>Chuck,
>>At first glance, it looks like you're storing the record number to a variable rather than a form property. This variable will go out of scope when you exit the method, unless you've declared it Public. Try again with a form property.
>>
>>Barbara
>>
>>>Barbara (and others who may read this),
>>>
>>>Thanks for your reply. I have indeed looked at the information in help, where they use the MOD() function for alternately colored grid rows. That example works great in my form; however, it's not quite exactly what I need. And when trying to implement what I need (which, by the way, seems to be simple) it's not working. Ugghhhh! The following code is a sample of some the things I've tried. It seems straight-forward and simple enough, does it not?...
>>>
>>>
>>>STORE RECNO() TO mSelectedRecord
>>>
>>>* Debugging information...
>>>MESSAGEBOX("What is mSelectedRecord? mSelectedRecord is:" + STR(mSelectedRecord))
>>>IIF(RECNO()=mSelectedRecord, MESSAGEBOX("RECNO() is equal to mSelectedRecord"), MESSAGEBOX("It doesn't"))
>>>* End of Debugging information
>>>
>>>ThisForm.Grid1.SetAll("DynamicBackColor", ;
>>>     "IIF(RECNO()=mSelectedRecord), RGB(255,255,255), RGB(0,255,0))", ;
>>>     "Column")
>>>
>>>
>>>When running this code, I do not get an error message, and there is absolutely no change in color at all on the grid.
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform