Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Cetin Basoz
  Where is Cetin Basoz?
 Izmir
 Turkey
 Cetin Basoz
 To: one delacruz
  
 
 
 one delacruz
 Tags
Subject: RE: grid's backcolor
Thread ID: 189325 Message ID: 189331 # Views: 2 # Ratings: 0
Version: Visual FoxPro 6 Category: Grids
Date: Thursday, August 14, 2008 12:22:13 PM         
   


> Hi,
>
> How to make the grid's backcolor change for the same items resulted from a query?
>
> TIA..

If I understand you right you want items groups to be in same color? ie:

Fruit,Apple: Yellow
Fruit,Orange: Yellow
Fruit,Banana: Yellow
Vegetable,Spinach: Green
...

If so then the code below does coloring by group (level there) in 3 different ways:

Public oForm1,oForm2,oForm3
oForm1 = Createobject('myForm1')
oForm2 = Createobject('myForm2')
oForm3 = Createobject('myForm3')
oForm1.Show()
oForm2.Show()
oForm3.Show()

oForm2.Left = oForm1.Width + 10
oForm3.Left = oForm2.Left + oForm2.Width + 10

Define Class myForm1 As Form
  Height = 400
  Width = 200
  Datasession = 2
  Add Object myGrid As Grid With Top = 5, Left=5, Height=360, Width=190
  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

Define Class myForm2 As Form
  Height = 400
  Width = 200
  DataSession=2
  Add Object myGrid As Grid With Top = 5, Left=5, Height=360, Width=190
  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

Define Class myForm3 As Form
  Height = 400
  Width = 200
  DataSession=2
  Add Object myGrid As Grid With Top = 5, Left=5, Height=360, Width=190
  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


Cetin Basoz

ENTIRE THREAD

grid's backcolor Posted by lopera @ 8/14/2008 12:10:51 PM
RE: grid's backcolor Posted by Mike Gagnon @ 8/14/2008 12:21:55 PM
RE: grid's backcolor Posted by Stefan Wuebbe @ 8/14/2008 12:22:02 PM
RE: grid's backcolor Posted by lopera @ 8/14/2008 12:23:45 PM
RE: grid's backcolor Posted by Stefan Wuebbe @ 8/14/2008 12:27:20 PM
RE: grid's backcolor Posted by Cetin Basoz @ 8/14/2008 12:22:13 PM