Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Different Colors for Rows of a Grid
Message
De
18/08/2007 04:59:30
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
18/08/2007 04:10:06
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
01248918
Message ID:
01248919
Vues:
28
>Hi all,
>
>I just want to set colors for the rows in my Grid on more than one condition.
>
>In the Init of Grid, I use:
>
>This.SetAll('dynamicbackcolor', 'iif(LEVELNO = 1, RGB(color1), RGB(color2) )' )
>
>This works fine when LEVELNO = 1 or Not. But I want to set diiferent colors when LEVELNO = 2 and LEVELNO = 3 etc.
>
>Please help me. Thanks a lot in advance.

There are many many ways to do that. Here are some of the ways:
Public oForm
oForm = Createobject('myForm')
oForm.Show()

Define Class myForm As Form
  Height = 400
  Width = 300
  Add Object myGrid As Grid With Top = 5, Left=5, Height=360, Width=290
  Add Object cmdColors As CommandButton With Top=365, Left=5,Caption='Set Color', AutoSize = .T.

  Procedure Load
    Create Cursor myData (Level i, myData c(10))
    Local ix
    For ix=1 To 100
      Insert Into myData Values ( Int(Rand()*10), Sys(2015) )
    Endfor
    Locate
  Endproc

  Procedure cmdColors.Click
    Create Cursor myColors (Color i)
    Insert Into myColors Values (0xFF0000)
    Insert Into myColors Values (0x00FF00)
    Insert Into myColors Values (0x0000FF)
    Insert Into myColors Values (0xFFFF00)
    Insert Into myColors Values (0xFF00FF)
    Insert Into myColors Values (0x00FFFF)
    Select myData
    Set Relation To Level Into myColors
    Thisform.myGrid.SetAll('DynamicBackColor',;
      'IIF(!eof("myColors"), myColors.Color, 0xFFFFFF)')
    Thisform.myGrid.Refresh()
  Endproc
Enddefine
PUBLIC oForm
oForm = CREATEOBJECT('myForm')
oForm.Show()

Define Class myForm As Form
  Height = 400
  Width = 300
  Add Object myGrid As Grid With Top = 5, Left=5, Height=360, Width=290
  Add Object cmdColors As CommandButton With Top=365, Left=5,Caption='Set Color', AutoSize = .T.

  Procedure Load
    Create Cursor myData (Level i, myData c(10))
    Local ix
    For ix=1 To 100
      Insert Into myData Values ( Int(Rand()*10), Sys(2015) )
    Endfor
    Locate
  Endproc

  Procedure cmdColors.Click
    TEXT to lcColors NOSHOW
0xFF0000
0x00FF00
0x0000FF
0xFFFF00
0xFF00FF
0x00FFFF
    ENDTEXT
    Thisform.AddProperty('myLevelColors', m.lcColors)
    Thisform.myGrid.SetAll('DynamicBackColor',;
      'IIF(BETWEEN(level,1,6), VAL(GETWORDNUM(thisform.myLevelColors,level)), 0xFFFFFF)')
    thisform.myGrid.Refresh()
  Endproc
Enddefine
Public oForm
oForm = Createobject('myForm')
oForm.Show()

Define Class myForm As Form
  Height = 400
  Width = 300
  Add Object myGrid As Grid With Top = 5, Left=5, Height=360, Width=290
  Add Object cmdColors As CommandButton With Top=365, Left=5,Caption='Set Color', AutoSize = .T.

  Procedure Load
    Create Cursor myData (Level i, myData c(10))
    Local ix
    For ix=1 To 100
      Insert Into myData Values ( Int(Rand()*10), Sys(2015) )
    Endfor
    Locate
  Endproc

  Procedure cmdColors.Click
    Thisform.myGrid.SetAll('DynamicBackColor','(thisform.GimmeColor(Level))')
    Thisform.myGrid.Refresh()
  Endproc

  Procedure GimmeColor(tnLevel)
    Do Case
      Case m.tnLevel=1
        Return 0xFF0000
      Case m.tnLevel=2
        Return 0x00FF00
      Case m.tnLevel=3
        Return 0x0000FF
      Case m.tnLevel=5
        Return 0xFFFF00
      Case m.tnLevel=7
        Return 0xFF00FF
      Case m.tnLevel=9
        Return 0x00FFFF
      Otherwise
        Return 0xFFFFFF
    Endcase
  Endproc
Enddefine
Last one is flexible enough to accomodate to very complex expressions.
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform