Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Grid Highlight Problem - Can you Duplicate it?
Message
De
13/09/2005 13:24:15
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Titre:
Grid Highlight Problem - Can you Duplicate it?
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
01049139
Message ID:
01049139
Vues:
83
I would appreciate if anyone willing to test this would. Watch the 3rd column highlighting in the code below. On my system, in both VFP8 and VFP9, on Windows XP when there is a special color in the background (as in row 1, column2) the 3rd column is not highlighted. Yet it should be. On the row where there is no special background color, the 3rd column highlights correctly. For example, in the test code below, run it and then use the down arrow to move through rows. The 3rd column only highlights correctly when the cursor is in the 3rd row where there is no special background color in the 2nd column. When there is a special background color, the background color should show, not the highlight and that part is working correctly in all rows. Are you seeing the same thing?
set safety OFF
set talk OFF
set exact ON
set near OFF
CLOSE TABLES all
CLOSE DATABASES all

CREATE TABLE tpolicy(po_number c(25), po_status c(3), po_name c(20))
APPEND BLANK
REPLACE po_name WITH "John T. Smith"
REPLACE po_number WITH "123456"
REPLACE po_status WITH "CXP"
APPEND BLANK
REPLACE po_name WITH "Sally A. Taylor"
REPLACE po_number WITH "789012"
REPLACE po_status WITH "NB"
APPEND BLANK
REPLACE po_name WITH "Craig Abernathy"
REPLACE po_number WITH "AAB123"
REPLACE po_status WITH "REN"
APPEND BLANK
REPLACE po_name WITH "Chris Johnson"
REPLACE po_number WITH "890123"
REPLACE po_status WITH "AP"
sele 0
CREATE TABLE vstatus (st_status c(3), st_attrib c(16))
APPEND BLANK
REPLACE st_status WITH "CXP"
REPLACE st_attrib WITH "RGB(255,128,192)"
APPEND BLANK
REPLACE st_status WITH "NB"
REPLACE st_attrib WITH "RGB(255,255,0)"
APPEND BLANK
REPLACE st_status WITH "AP"
REPLACE st_attrib WITH "RGB(128,255,255)"

COPY TO ARRAY _vstatus FIELDS ST_STATUS, ST_ATTRIB FOR !EMPTY(ST_STATUS)

SELE tpolicy
GO top

oform = createobj('testform')

oform.show()
oform.SetPolicyGridColor()
oform.refresh()

read events

CLOSE ALL
return

DEFINE CLASS testform AS form


   Top = 0
   Left = 0
   Height = 227
   Width = 461
   DoCreate = .T.
   Caption = "Test Highlight Change "
   *-- Specifies the grid's selected row background color.
   highlightbackcolor = .F.
   *-- Specifies whether the selected row is highlighted and also if it remains highlighted when user changes focus to another control on the form.
   highlightstyle = .F.
   gridbackcolor = .F.
   gridforecolor = .F.
   Name = "TESTFORM"


   ADD OBJECT grid1 AS grid WITH ;
      ColumnCount = 3, ;
      Height = 200, ;
      Left = 24, ;
      Panel = 1, ;
      RecordSource = "tpolicy", ;
      RecordSourceType = 1, ;
      Top = 12, ;
      Width = 410, ;
      HighlightBackColor = RGB(0,128,192), ;
      HighlightForeColor = RGB(0,0,0), ;
      SelectedItemBackColor = RGB(0,128,192), ;
      SelectedItemForeColor = RGB(0,0,0), ;
      HighlightStyle = 2, ;
      Name = "grid1", ;
      Column1.ControlSource = "tpolicy.po_number", ;
      Column1.Width = 154, ;
      Column1.Name = "Column1", ;
      Column2.ControlSource = "tpolicy.po_status", ;
      Column2.Name = "Column2",;
      Column3.ControlSource = "tpolicy.po_name", ;
      Column3.Width = 154, ;
      Column3.Name = "Column3"


   PROCEDURE setpolicygridcolor
      WITH this.grid1
         FOR nColumnID = 1 TO .columncount
            colorvalue = thisform.getpolicygridcolor(.recordsource,.columns(nColumnID).controlsource)
            .Columns(nColumnID).dynamicbackcolor = colorvalue
         ENDFOR
      ENDWITH
   ENDPROC


   PROCEDURE getpolicygridcolor
      LPARAMETERS tcolortable, tcolorfield

      EXTERNAL ARRAY _vstatus
      EXTERNAL ARRAY _vtype

      defaultcolorvalue = "RGB(255,255,255)"

      IF EMPTY(tcolortable) .OR. TYPE('tcolortable') <> "C" .OR. !USED(tcolortable)
         RETURN defaultcolorvalue
      ENDIF
      IF TYPE('tcolorfield') <> "C" .OR. EMPTY(tcolorfield)
         RETURN defaultcolorvalue
      ENDIF
      IF AT('.',tcolorfield) > 0
         tcolorfield = SUBSTR(tcolorfield,AT('.',tcolorfield)+1)
      ENDIF

      tcolorfield = UPPER(ALLTRIM(tcolorfield))

      SELECT (tcolortable)

      DO CASE
         CASE tcolorfield = "PO_SUSP"
            RETURN "IIF(!EMPTY(po_status),IIF(ASCAN(_vstatus,po_status)>0,IIF(!EMPTY(_vstatus(ASCAN(_vstatus,po_status)+1)),EVALUATE(_vstatus(ASCAN(_vstatus,po_status)+1)),RGB(255,255,255)),RGB(255,255,255)),RGB(255,255,255))"
         CASE tcolorfield = "PO_STATUS"
            RETURN "IIF(!EMPTY(po_status),IIF(ASCAN(_vstatus,po_status)>0,IIF(!EMPTY(_vstatus(ASCAN(_vstatus,po_status)+1)),EVALUATE(_vstatus(ASCAN(_vstatus,po_status)+1)),RGB(255,255,255)),RGB(255,255,255)),RGB(255,255,255))"
         CASE tcolorfield = "PO_TYPE"
            RETURN "IIF(!EMPTY(po_type),IIF(ASCAN(_vtype,po_type)>0,IIF(!EMPTY(_vtype(ASCAN(_vtype,po_type)+2)),EVALUATE(_vtype(ASCAN(_vtype,po_type)+2)),RGB(255,255,255)),RGB(255,255,255)),RGB(255,255,255))"
      ENDCASE

      RETURN defaultcolorvalue
   ENDPROC


   PROCEDURE highlight_row
      THISFORM.LOCKSCREEN = .T.

      PRIVATE llsethighlight
      llsethighlight = .F.

      WITH THISFORM.grid1

         FOR lnColumn = 1 TO .COLUMNCOUNT

*           .COLUMNS(lnColumn).SPARSE = .f.   && default all columns to .t.

            PRIVATE loCurrentControl
            STORE NULL TO loCurrentControl
            FOR EACH loControl IN .COLUMNS(lnColumn).CONTROLS
               IF loControl.NAME = loControl.PARENT.CURRENTCONTROL
                  loCurrentControl = loControl
               ENDIF
            ENDFOR

            IF TYPE("loCurrentControl") = "O" AND NOT ISNULL(loCurrentControl)
               IF LOWER(loCurrentControl.BASECLASS) = "textbox" .OR. LOWER(loCurrentControl.BASECLASS) = "editbox"
                  IF PEMSTATUS(loCurrentControl, "BackColor", 5 ) && Some controls in the column (i.e. Image) may not have .BackColor Property
                     IF !EMPTY(.COLUMNS(lnColumn).DYNAMICBACKCOLOR)
                        loCurrentControl.BACKCOLOR = EVALUATE(.COLUMNS(lnColumn).DYNAMICBACKCOLOR)
                        IF loCurrentControl.BACKCOLOR = THISFORM.gridbackcolor
                           loCurrentControl.BACKCOLOR = THISFORM.HIGHLIGHTBACKCOLOR
*                        .Columns(lnColumn).Sparse = .t.
                        ELSE
*                           .COLUMNS(lnColumn).SPARSE = .F.
                           llsethighlight = .T.   && change the highlightstyle on the grid
                        ENDIF
                     ELSE
*                        .Columns(lnColumn).Sparse = .t.
                        loCurrentControl.BACKCOLOR = THISFORM.HIGHLIGHTBACKCOLOR
                     ENDIF
                  ENDIF
               ENDIF
            ENDIF

         ENDFOR

         IF llsethighlight
            .HIGHLIGHTSTYLE = 0   && do not show the highlight - we emulate a highlight
         ELSE
            .HIGHLIGHTSTYLE = THISFORM.HIGHLIGHTSTYLE && set the highlight back to the default
         ENDIF

      ENDWITH

      THISFORM.LOCKSCREEN = .F.
   ENDPROC


   PROCEDURE Destroy
      DODEFAULT()
      CLEAR EVENTS
   ENDPROC


   PROCEDURE Init
      DODEFAULT()
      WITH this.grid1
         thisform.highlightbackcolor = .highlightbackcolor
         thisform.highlightstyle     = .highlightstyle
         thisform.gridbackcolor      = .backcolor
         thisform.gridforecolor      = .forecolor
      ENDWITH
      this.highlight_row()
   ENDPROC


   PROCEDURE grid1.AfterRowColChange
      LPARAMETERS nColIndex
      thisform.highlight_row()
   ENDPROC


ENDDEFINE

OK this one seems to work:
SET SAFETY OFF
SET TALK OFF
SET EXACT ON
SET NEAR OFF
CLOSE TABLES ALL
CLOSE DATABASES ALL

CREATE TABLE tpolicy(po_number c(25), po_status c(3), po_name c(20))
APPEND BLANK
REPLACE po_name WITH "John T. Smith"
REPLACE po_number WITH "123456"
REPLACE po_status WITH "CXP"
APPEND BLANK
REPLACE po_name WITH "Sally A. Taylor"
REPLACE po_number WITH "789012"
REPLACE po_status WITH "NB"
APPEND BLANK
REPLACE po_name WITH "Craig Abernathy"
REPLACE po_number WITH "AAB123"
REPLACE po_status WITH "REN"
APPEND BLANK
REPLACE po_name WITH "Chris Johnson"
REPLACE po_number WITH "890123"
REPLACE po_status WITH "AP"
SELE 0
CREATE TABLE vstatus (st_status c(3), st_attrib c(16))
APPEND BLANK
REPLACE st_status WITH "CXP"
REPLACE st_attrib WITH "RGB(255,128,192)"
APPEND BLANK
REPLACE st_status WITH "NB"
REPLACE st_attrib WITH "RGB(255,255,0)"
APPEND BLANK
REPLACE st_status WITH "AP"
REPLACE st_attrib WITH "RGB(128,255,255)"

COPY TO ARRAY _vstatus FIELDS st_status, st_attrib FOR !EMPTY(st_status)

SELE tpolicy
GO TOP

oform = CREATEOBJ('testform')

oform.SHOW()
oform.SetPolicyGridColor()
oform.REFRESH()

READ EVENTS

CLOSE ALL
RETURN

DEFINE CLASS testform AS FORM


   TOP = 0
   LEFT = 0
   HEIGHT = 227
   WIDTH = 461
   DOCREATE = .T.
   CAPTION = "Test Highlight Change "
   *-- Specifies the grid's selected row background color.
   HIGHLIGHTBACKCOLOR = .F.
   *-- Specifies whether the selected row is highlighted and also if it remains highlighted when user changes focus to another control on the form.
   HIGHLIGHTSTYLE = .F.
   gridbackcolor = .F.
   gridforecolor = .F.
   NAME = "TESTFORM"


   ADD OBJECT grid1 AS GRID WITH ;
      COLUMNCOUNT = 3, ;
      HEIGHT = 200, ;
      LEFT = 24, ;
      PANEL = 1, ;
      RECORDSOURCE = "tpolicy", ;
      RECORDSOURCETYPE = 1, ;
      TOP = 12, ;
      WIDTH = 410, ;
      HIGHLIGHTBACKCOLOR = RGB(0,128,192), ;
      HIGHLIGHTFORECOLOR = RGB(0,0,0), ;
      SELECTEDITEMBACKCOLOR = RGB(0,128,192), ;
      SELECTEDITEMFORECOLOR = RGB(0,0,0), ;
      HIGHLIGHTSTYLE = 2, ;
      NAME = "grid1", ;
      Column1.CONTROLSOURCE = "tpolicy.po_number", ;
      Column1.WIDTH = 154, ;
      Column1.NAME = "Column1", ;
      Column2.CONTROLSOURCE = "tpolicy.po_status", ;
      Column2.NAME = "Column2",;
      Column3.CONTROLSOURCE = "tpolicy.po_name", ;
      Column3.WIDTH = 154, ;
      Column3.NAME = "Column3"


   PROCEDURE SetPolicyGridColor
   WITH THIS.grid1
      FOR nColumnID = 1 TO .COLUMNCOUNT
         colorvalue = THISFORM.getpolicygridcolor(.RECORDSOURCE,.COLUMNS(nColumnID).CONTROLSOURCE)
         .COLUMNS(nColumnID).DYNAMICBACKCOLOR = colorvalue
      ENDFOR
   ENDWITH
   ENDPROC


   PROCEDURE getpolicygridcolor
   LPARAMETERS tcolortable, tcolorfield

   EXTERNAL ARRAY _vstatus
   EXTERNAL ARRAY _vtype

   defaultcolorvalue = "RGB(255,255,255)"

   IF EMPTY(tcolortable) .OR. TYPE('tcolortable') <> "C" .OR. !USED(tcolortable)
      RETURN defaultcolorvalue
   ENDIF
   IF TYPE('tcolorfield') <> "C" .OR. EMPTY(tcolorfield)
      RETURN defaultcolorvalue
   ENDIF
   IF AT('.',tcolorfield) > 0
      tcolorfield = SUBSTR(tcolorfield,AT('.',tcolorfield)+1)
   ENDIF

   tcolorfield = UPPER(ALLTRIM(tcolorfield))

   SELECT (tcolortable)

   DO CASE
      CASE tcolorfield = "PO_SUSP"
         RETURN "IIF(!EMPTY(po_status),IIF(ASCAN(_vstatus,po_status)>0,IIF(!EMPTY(_vstatus(ASCAN(_vstatus,po_status)+1)),EVALUATE(_vstatus(ASCAN(_vstatus,po_status)+1)),RGB(255,255,255)),RGB(255,255,255)),RGB(255,255,255))"
      CASE tcolorfield = "PO_STATUS"
         RETURN "IIF(!EMPTY(po_status),IIF(ASCAN(_vstatus,po_status)>0,IIF(!EMPTY(_vstatus(ASCAN(_vstatus,po_status)+1)),EVALUATE(_vstatus(ASCAN(_vstatus,po_status)+1)),RGB(255,255,255)),RGB(255,255,255)),RGB(255,255,255))"
      CASE tcolorfield = "PO_TYPE"
         RETURN "IIF(!EMPTY(po_type),IIF(ASCAN(_vtype,po_type)>0,IIF(!EMPTY(_vtype(ASCAN(_vtype,po_type)+2)),EVALUATE(_vtype(ASCAN(_vtype,po_type)+2)),RGB(255,255,255)),RGB(255,255,255)),RGB(255,255,255))"
   ENDCASE

   RETURN defaultcolorvalue
   ENDPROC


   PROCEDURE highlight_row
   THISFORM.LOCKSCREEN = .T.

   PRIVATE llsethighlight
   llsethighlight = .F.

   WITH THISFORM.grid1

      FOR lnColumn = 1 TO .COLUMNCOUNT

         IF .COLUMNS(lnColumn).CONTROLSOURCE == "PO_STATUS" ;
               .OR. .COLUMNS(lnColumn).CONTROLSOURCE == "PO_TYPE"

            .COLUMNS(lnColumn).SPARSE = .F.

            PRIVATE loCurrentControl
            STORE NULL TO loCurrentControl
            FOR EACH loControl IN .COLUMNS(lnColumn).CONTROLS
               IF loControl.NAME = loControl.PARENT.CURRENTCONTROL
                  loCurrentControl = loControl
               ENDIF
            ENDFOR

            IF TYPE("loCurrentControl") = "O" AND NOT ISNULL(loCurrentControl)
               IF LOWER(loCurrentControl.BASECLASS) = "textbox" .OR. LOWER(loCurrentControl.BASECLASS) = "editbox"
                  IF PEMSTATUS(loCurrentControl, "BackColor", 5 ) && Some controls in the column (i.e. Image) may not have .BackColor Property
                     IF !EMPTY(.COLUMNS(lnColumn).DYNAMICBACKCOLOR)
                        loCurrentControl.BACKCOLOR = EVALUATE(.COLUMNS(lnColumn).DYNAMICBACKCOLOR)
                        IF loCurrentControl.BACKCOLOR = THISFORM.gridbackcolor
                           loCurrentControl.BACKCOLOR = THISFORM.HIGHLIGHTBACKCOLOR
                           .COLUMNS(lnColumn).SPARSE = .T.
                        ENDIF
                     ELSE
                        loCurrentControl.BACKCOLOR = THISFORM.HIGHLIGHTBACKCOLOR
                        .COLUMNS(lnColumn).SPARSE = .T.
                     ENDIF
                     IF loCurrentControl.BACKCOLOR <> THISFORM.gridbackcolor
                        llsethighlight = .T.
                     ELSE
                        loCurrentControl.BACKCOLOR = THISFORM.HIGHLIGHTBACKCOLOR
                        .COLUMNS(lnColumn).SPARSE = .T.
                     ENDIF
                  ENDIF
               ENDIF
            ENDIF
         ENDIF

      ENDFOR

      IF llsethighlight
         .HIGHLIGHTSTYLE = 0
      ELSE
         .HIGHLIGHTSTYLE = THISFORM.HIGHLIGHTSTYLE
      ENDIF

   ENDWITH

   THISFORM.LOCKSCREEN = .F.
   ENDPROC


   PROCEDURE DESTROY
   DODEFAULT()
   CLEAR EVENTS
   ENDPROC


   PROCEDURE INIT
   DODEFAULT()
   WITH THIS.grid1
      THISFORM.HIGHLIGHTBACKCOLOR = .HIGHLIGHTBACKCOLOR
      THISFORM.HIGHLIGHTSTYLE     = .HIGHLIGHTSTYLE
      THISFORM.gridbackcolor      = .BACKCOLOR
      THISFORM.gridforecolor      = .FORECOLOR
   ENDWITH
   THIS.highlight_row()
   ENDPROC


   PROCEDURE grid1.AFTERROWCOLCHANGE
   LPARAMETERS nColIndex
   THISFORM.highlight_row()
   ENDPROC


ENDDEFINE
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform