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!

Dynamic Header color in Grid?

Status
Not open for further replies.

rkolva

Programmer
Jan 16, 2003
127
US
I've been at a loss at how to do something that seems so simple from looking at the property sheet of the grid control. I have a grid that my user can re-order by clicking on any column header and would like to give some visual clue as to which column has the current sort order. At the moment the best I have come up with is to underline the Header text.

My first choice would be to include some indication if the order were Ascending or Descending (a little triangle maybe). Barring that it would be nice to toggle the header colors.

I have been at this for a couple of hours with no success, any ideas?

Thanks,

Ralph Kolva
 
Ralph,

Code:
thisform.MyGrid.column1.Header1.BackColor = 255

Works for me.

Or, you can add a small image to the header. That's what I do. I have a pair of images that look like upward- and downward-pointing arrows:

Code:
thisform.MyGrid.column1.Header1.Picture = "ascending.gif"

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Code:
oForm = CREATEOBJECT([Form1])
oForm.Show(1)

*
DEFINE CLASS form1 AS Form


    Top = 0
    Left = 0
    Height = 490
    Width = 725
    DoCreate = .T.
    Name = "Aladinform1"

    ADD OBJECT grid1 AS grid WITH ;
        ColumnCount = 3, ;
        Height = 200, ;
        Left = 52, ;
        Top = 58, ;
        Width = 320, ;
        Themes = .F., ;
        Name = "Grid1", ;
        Column1.Name = "Column1", ;
        Column2.Name = "Column2", ;
        Column3.Name = "Column3"

    PROCEDURE Init
        FOR EACH oCol IN thisform.Grid1.Columns
            BINDEVENT(oCol.Header1,[Click],thisform,[setheader],1)
        NEXT


    PROCEDURE setheader
        AEVENTS(laEvents,0)
        loHeader = laEvents[1]
        LOCAL loColumn 
        loColumn = loHeader.Parent
        FOR EACH oCol IN thisform.Grid1.Columns
            IF NOT UPPER(oCol.Name) == UPPER(loColumn.Name)
               oCol.Header1.BackColor = RGB(236,233,216)
            ENDIF
        NEXT
        IF loHeader.BackColor = RGB(255,0,255) && Ascending
           loHeader.BackColor = RGB(0,255,0) && Set to Descending
        **   SET ORDER TO ..... DESCENDING
        ELSE 
           loHeader.BackColor = RGB(255,0,255) && Set to ascending
        **   SET ORDER TO ..... ASCENDING
        ENDIF
    ENDPROC


    PROCEDURE Load
        CREATE CURSOR crsTest (Fld1 I, Fld2 char(20), fld3 D)
        FOR lnFor = 1 TO 20
            INSERT INTO crsTest VALUES (lnFor, REPLICATE([A],lnFor), DATE()+lnFor)
        NEXT
        GO TOP
    ENDPROC

ENDDEFINE

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Thanks for the reply Mike and Borislav,

Ok, then is there some other setting that is keeping this from working in my grid because it's just not happening?

Stepping through the debugger I can see the BackColor value change but the color never does. My code is not that much different from Borislav's but where his grid does what I would expect mine doesn't.

Code:
FOR EACH oColumn IN THISFORM.DesGRID.Columns
  IF oColumn.ControlSource == vsControlSource THEN
    IF vlOnOff THEN		
      oColumn.Header1.FontUnderline = .T.
      oColumn.Header1.BackColor     = 16711680		
    ELSE
      oColumn.Header1.FontUnderline = .F.
      oColumn.Header1.BackColor     = 14215660
    ENDIF
  ELSE
    oColumn.Header1.FontUnderline   = .F.
    oColumn.Header1.BackColor       = 14215660
  ENDIF
NEXT

Ralph Kolva
 
Set Grid.Themes = .f.

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Thanks Borislav,

That was the one! To think that I spent hours trying to figure out why it wasn't changing colors and all it was was a themes setting! Oh well, I decided to go Mike's route and use little triangles to indicate the direction of the sort order but it's nice to know why it wasn't working. Thanks to you both again.

Ralph Kolva
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top