Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Form.Grid.Header.Click()
Message
 
 
To
09/07/1999 19:35:21
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
00239710
Message ID:
00239712
Views:
20
Tim,

You can replace the header objects at runtime to allow this sort of functionality. The only thing is a Header class must be defined in a PRG it can't be visually designed. You just use the Column.RemoveObject() method to get rid of the default header and Column.AddObject() your class back in. Here's the code for my Header class it should give you an idea or two.
* ccontrol.prg 

* 26-Oct-98 major rev

define class hdrSeeker as Header

Name = "hdrSeeker"
mcArrowName = ""    && name of the arrow used for all headers of the grid
mlAscending = .f.   && flag for sort order
mlColumnMoved = .f. && flag indicating column was moved
mnColumnOrder = 0   && original column order
mlColumnSized = .f. && flag indicating column was resized
mnColumnWidth = 0   && original size of column
mcTag = ""          && name of the index tag

procedure Init( pcTag )
local lcName

this.mcTag = iif( ! empty( pcTag ), pcTag, "" )
this.FontBold = ! empty( this.mcTag )

lcName = this.parent.parent.Name + "lblHeaderArrow"
this.mcArrowName = "this.parent.parent.parent." + lcName

if ( type( (this.mcArrowName) ) == "U" )
   * arrow doesn't exist yet so create it
   lcGrid = FullName( this.parent.parent )
   lcGrid = "thisform" + substr( lcGrid, at( '.', lcGrid ) )
   this.parent.parent.parent.AddObject( (lcName), "lblHeaderArrow", lcGrid )
endif

if ( ! empty( this.mcTag ) )
   this.parent.Width = this.parent.Width + 5
endif

endproc

procedure Click()
local loArrow

loArrow = evaluate( this.mcArrowName )

if ( ! empty( this.mcTag ) and ! this.mlColumnMoved and ! this.mlColumnSized )
   * sortable column that was clicked
   this.mlAscending = ! this.mlAscending
   this.parent.parent.Reorder( this.mcTag, this.mlAscending )
   loArrow.mcColumnName = this.parent.Name
endif

loArrow.SetPosition() && update position
endproc

procedure MouseDown
LPARAMETERS nButton, nShift, nXCoord, nYCoord

with this
   * initialize items that will be tested in MouseUp
   .mnColumnOrder = this.parent.ColumnOrder
   .mnColumnWidth = this.parent.Width
endwith
endproc

procedure MouseUp
LPARAMETERS nButton, nShift, nXCoord, nYCoord

with this
   * check to see if this was a resize or move
   .mlColumnMoved = ( this.parent.ColumnOrder != .mnColumnOrder )
   .mlColumnSized = ( this.parent.Width != .mnColumnWidth )
endwith
endproc

procedure Error
LPARAMETERS nError, cMethod, nLine
ObjError( this, nError, cMethod, nLine )
endproc

enddefine
>I use the default grid (.columncount=-1) and apply different views to control the columns that appear in the grid. This is fast and seems to works well for what I am doing. The problem is my users want to sort the grid on the fly by clicking on the header. This is easy to do if you define your columns at design time but I have yet to figure out how to do it at runtime.
>
>Please tell me this CAN be done!
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform