Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
ListView Control 6.0
Message
De
31/01/2002 16:59:13
 
 
À
31/01/2002 16:10:07
Information générale
Forum:
Visual FoxPro
Catégorie:
Contrôles ActiveX en VFP
Divers
Thread ID:
00613692
Message ID:
00613726
Vues:
9
Hello Mike.

Hi, I'm new to using ActiveX Controls in VFP. With using the Microsoft ListView Control 6.0, how would I go about populating that list with data from a table???

This code, in the Init() of the Listview, will populate a listview with the fields in alias that is open in the currently selected work area:
This.View = 3
lcCursor = ALIAS()
lnFldCount = AFIELDS( laFields, lcCursor )
lnIndex	= 0
FOR lnCnt = 1 TO lnFldCount
  lnIndex = lnIndex + 1
  DIMENSION This.aDisplayFields[ lnIndex, 2 ]
  This.aDisplayFields[ lnIndex, 1 ] = laFields[ lnCnt, 1 ]
  *** Now, if we have a caption available, use that for the header
  *** So check to see if the data source is in a dbc and retrieve the caption
  *** if it is, otherwise use the name of the field
  lcDbc	= CURSORGETPROP( "Database", lcCursor )	
  IF NOT EMPTY( lcDbc )
    *** Make sure it is the current database
    SET DATABASE TO ( lcDBC )
    *** Get the caption for this field
    lcCaption = DBGETPROP( lcCursor + '.' + laFields[ lnCnt, 1 ], 'Field', 'Caption' )
    IF EMPTY( lcCaption )
      lcCaption = laFields[ lnCnt, 1 ]
    ENDIF
    This.aDisplayFields[ lnIndex, 2 ] = lcCaption
  ELSE
    This.aDisplayFields[ lnIndex, 2 ] = laFields[ lnCnt, 1 ]
  ENDIF
ENDFOR
*** Must Add the Column Headers for all the we are going to display Items in the cursor
lnColumnCount = ALEN( This.aDisplayFields, 1 )
WITH This.ColumnHeaders 
  FOR lnItem = 1 TO ALEN( This.aDisplayFields, 1 )
    *** Calculate the width for this column
    lnHdrWidth = ( LEN( This.aDisplayFields[ lnItem, 2 ] ) + 16 ) * FONTMETRIC( 6, 'Arial', 9 )
    lnColWidth = LEN( TRANSFORM( EVALUATE( lcCursor + '. ' + This.aDisplayFields[ lnItem, 1 ] ) ) ) * FONTMETRIC( 6, 'Arial', 9 )
    IF lnColWidth < lnHdrWidth
      lnColWidth = lnHdrWidth
    ENDIF
      .Add( , , This.aDisplayFields[ lnItem, 2 ], lnColWidth,  lvwColumnLeft )
  ENDFOR
ENDWITH
*** Now populate all the rows
WITH This.ListItems 
  *** Add the ListItem for this Record
  *** And set the ListItem's Key to the Name of the cursor and PK field of the data source
  loItem = .Add( , lcCursor + '_' + ALLTRIM( TRANSFORM( EVALUATE( lcCursor + '.' + This.cPkField ) ) ), ;
   ALLTRIM( TRANSFORM( EVALUATE( lcCursor + '.' + This.aDisplayFields[ 1, 1 ] ) ) ) )
  *** Use fields 2 - n to populate the list's SubItems
  WITH loItem
    FOR lnItem = 2 TO ALEN( This.aDisplayFields, 1 )
      .SubItems( lnItem - 1 ) = ALLTRIM( TRANSFORM( EVALUATE( lcCursor + '.' + This.aDisplayFields[ lnItem, 1 ] ) ) ) 
    ENDFOR
  ENDWITH
ENDWITH
HTH
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform