Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to use DynamicBackColor w/o using RECNO()
Message
From
03/02/2007 08:28:27
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
03/02/2007 02:19:49
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
01192085
Message ID:
01192098
Views:
47
This message has been marked as the solution to the initial question of the thread.
>Hi All,
>
>I would like to show records via a grid control with an alternating backcolor.
>
>The following works well if based on the RECNO() function, like so:
>
>
>frmMyForm.grdGrid1.SetAll("DynamicBackColor", ;
>   "IIF(MOD(RECNO( ), 2)=0, RGB(255,255,255) ;
>   , RGB(0,255,0))", "Column")
>
>
>If I change the controlling order of the underlying table however, it obviously won't work.
>
>How do I maintain the alternating backcolor even with different controlling order?
>
>Thanks in advance,
>
>Dennis

Dennis,
Use an auxillary cursor (or array if you don't have limit problem). ie:
Public oform1

oform1=Newobject("form1")
oform1.Show
Return

Define Class form1 As Form
  DataSession = 2
  Top = 0
  Left = 0
  Height = 325
  Width = 564
  DoCreate = .T.
  Caption = "Form1"
  Name = "Form1"

  Add Object grdcustomer As Grid With ;
    ColumnCount = 12, ;
    Height = 273, ;
    Left = 11, ;
    RecordSource = "customer", ;
    RecordSourceType = 1, ;
    Top = 5, ;
    Width = 541, ;
    Name = "grdCustomer"

  Add Object combo1 As ComboBox With ;
    Height = 24, ;
    Left = 108, ;
    Top = 288, ;
    Width = 132, ;
    Name = "Combo1"


  Add Object label1 As Label With ;
    Caption = "Change tag to", ;
    Height = 17, ;
    Left = 12, ;
    Top = 292, ;
    Width = 84, ;
    Name = "Label1"


  Procedure Init
    With This.grdcustomer
      .AddProperty('CurrentOrder',0)
      Select Recno() As RcNo, 1 As OrderCol ;
        from (.RecordSource) ;
        order By OrderCol  ;
        into Cursor crsOrdering ;
        readwrite
      Select crsOrdering
      Index On RcNo Tag RcNo

      Select (.RecordSource)
      Local lcAlternatingExpression
      lcAlternatingExpression = "Recno('crsOrdering')%2=0"
      *!*	Borrowed expression from Fabio Lunardon - alternate in 2 rows groups
      *!*   lcAlternatingExpression = "BitTest((Recno('crsOrdering')-1)/2,0)"

      .SetAll("DynamicBackColor", ;
        "IIF(Seek(Recno(this.recordsource),'crsOrdering','rcno') and "+;
        m.lcAlternatingExpression+",0xC0C0C0,0xFFFFFF)", "Column")
    Endwith
  Endproc

  Procedure grdcustomer.Refresh
    Local lcOrder, lnOrder
    With This
      Select (.RecordSource)
      lnOrder = Val(Sys(21))
      If .CurrentOrder # m.lnOrder
        lcOrder = Iif(m.lnOrder = 0,'1',Key(m.lnOrder))
        Select Recno() As RcNo, &lcOrder As OrderCol ;
          from (.RecordSource) ;
          order By OrderCol  ;
          into Cursor crsOrdering ;
          readwrite
        Select crsOrdering
        Index On RcNo Tag RcNo
        Select (.RecordSource)
        .CurrentOrder = m.lnOrder
      Endif
    Endwith
  Endproc


  Procedure combo1.InteractiveChange
    Select customer
    If ( This.Value == "None" )
      Set Order To 0
    Else
      Set Order To Tag (This.Value)
    Endif
    Thisform.grdcustomer.Refresh()
  Endproc


  Procedure combo1.Init
    Select customer
    This.AddItem( "None" )
    For ix=1 To Tagcount()
      This.AddItem( Tag(ix) )
    Endfor
  Endproc

  Procedure Load
    Use (_samples+'data\customer')
  Endproc
Enddefine
PS: Another simple trick is keeping a string reccount() length and setting individual record positions to a color index (up to 256 color index per record.
Cetin
Ç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
Next
Reply
Map
View

Click here to load this message in the networking platform