Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Multi-line grid headers
Message
De
24/11/1999 04:38:18
 
 
À
23/11/1999 15:50:20
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00294587
Message ID:
00294865
Vues:
21
Hi Mark.

>> Can a grid have more than one line in the headers, and still allow the end user to move the columns? <<

yes, but it is an expensive proposition < s >. Add 2 custom methods to your grid class: SetHeaders and RefreshHeaders. Call SetHeaders from the Init of the grid class. If you want the grid to scroll horizontally, call RefreshHeaders from the grid's scrolled method as well as from the AfterRowColChange (because if the grid scrolls as a result of hitting the TAB key or a cursor key, the grid's scrolled event does not fire). RefreshHeaders is also called from each column's moved and resize method. You also need to do some funky zOrder stuff in the GotFocus method of every other control on the form as well as in the form's LostFocus method because, if you don't, the grid's multi-line headers disappear when another object on the form gets focus or when focus moves to another form. This code assumes that the grid's header are set tall enough in the form designer to accomodate the multi-line headers. Here is the Setheaders method:
LOCAL lnCol, lcName

WITH This
  *** Get the x co-ordinate of the rightmost position in the visible
  *** portion of the grid so if we have columns that are not visible
  *** we don't make the labels for their headers visible
  .nRight = .Left + .Width - IIF( .ScrollBars > 1, SYSMETRIC(5), 0 )

  *** Loop through the grid's columns and create the labels to float
  *** on top of the headers
  FOR lnCol = 1 TO .ColumnCount
    lcName = "dHeader" + LTRIM( STR( lnCol ) )
    This.Parent.Addobject(lcName, "Label")
    WITH EVAL("This.Parent." + lcName)
      *** Give the label the correct appearance
      .BackStyle = 0		&& Transparent
      .BorderStyle = 0		&& No Border
      .Alignment = 2		&& Center alignment looks best 
      .WordWrap	= .T.
      .Caption = This.Columns[ lnCol ].Controls[ 1 ].Caption
      .FontName	= This.Columns[ lnCol ].Controls[ 1 ].Fontname
      .FontSize	= This.Columns[ lnCol ].Controls[ 1 ].FontSize
      .FontBold	= This.Columns[ lnCol ].Controls[ 1 ].FontBold
      .Top = This.Top + This.nHdrMargin
      .Height = This.HeaderHeight - ( 2 * This.nHdrMargin )			
      This.Columns[ lnCol ].Controls[ 1 ].Caption = SPACE(0)
    ENDWITH
  ENDFOR
  *** Now set the left and width properties for the labels
  .RefreshHeaders()
ENDWITH
And this is what goes into RefreshHeaders:
LOCAL lnCol, lcName, lnHdrLeft, lnHdrWidth

Thisform.LockScreen = .T.
WITH This
  FOR lnCol = 1 TO .ColumnCount
    lcName = "dHeader" + LTRIM( STR( lnCol ) )
    WITH EVAL("This.Parent." + lcName)
      lnHdrWidth = This.Columns[ lnCol ].Width - ( 2 * This.nHdrMargin ) 
      .Width = IIF( lnHdrWidth > 0, lnHdrWidth, 0 )
      *** Only set the left and visible properties if this column in visible
      lnHdrLeft = OBJTOCLIENT( This.Columns[ lnCol ].Controls[ 1 ], 2 )
      *** If we are in a container, find out the offset from the form
      *** and adjust the left value
      IF UPPER( This.Parent.BaseClass ) # 'FORM'
        lnHdrLeft = lnHdrLeft - OBJTOCLIENT( This.Parent, 2 ) 
      ENDIF	
      IF lnHdrLeft > 0
        .Left = lnHdrLeft + This.nHdrMargin
        .Visible = .T.
        *** make sure that the width doesn't overflow the visible
        *** portion of the grid
        IF .Left + .Width > This.nRight
          lnHdrWidth = This.nRight - .Left - ( 2 * This.nHdrMargin )
          .Width = IIF( lnHdrWidth > 0, lnHdrWidth, 0 )
        ENDIF	
      ELSE
        .Visible = .F.
      ENDIF	
    ENDWITH
  ENDFOR
ENDWITH
Thisform.LockScreen = .F.
Like I said, it CAN be done, but it is expensive < s >.

Marcia
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform