Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Grids and Headers
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
00203839
Message ID:
00203923
Vues:
16
> I'm trying to create a class based on Grid control that dynamically got
> the recordsource throught a SQL statement. Until here, it's all OK.
> My problem is I'll like when the header of a column is clicked, this
> column has been sorted. Then, I need write code for the header click.

You can create a header and column class especially for your grid. Here's how:
DEFINE CLASS MyHeader AS Header
    FUNCTION Click
        THIS.Parent.Parent.DoSort(THIS.Parent.ControlSource)
    ENDFUNC
ENDDEFINE

DEFINE CLASS MyColumn AS Column
    FUNCTION Init
        THIS.RemoveObject("Header1")
        THIS.AddObject("Header1","MyHeader")
    ENDFUNC
ENDDEFINE
When you generate your cursor, the grid gets populated automatically in case the ColumnCount proeprty is set to -1. However, that's not what you want. You set the ColumnCount property to 0 and populate the grid yourself. Here's how:
THISFORM.oGrid.RecordSource = "MyCursor"
THISFORM.oGrid.ColumnCount = 0
FOR lnCounter = 1 TO FCount()
    lcObject = "Column"+Trans(lnCounter)
    THIS.oGrid.AddObject(lcObject,"MyColumn")
    THIS.oGrid.&lcObject..ControlSource = Field(lnCounter)
    THIS.oGrid.&lcObject..Header1.Caption = Field(lnCounter)
ENDFOR
Of course, you now also need some code in the grid that sets the order. In the example above, I assume there is a DoSort() method.

Markus




Markus Egger
President, EPS Software Corp
Author, Advanced Object Oriented Programming with VFP6
Publisher, CoDe Magazine
Microsoft MVP since 1995
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform