Re: Grid Column Header
- From: "Dorian C. Chalom" <DChalom@xxxxxxxxxxx>
- Date: Mon, 3 Jul 2006 11:59:46 -0400
Thats what I was afraid of. So now I must now create a PRG file just to
hold the definition of this Header Class.
"Fred Taylor" <ftaylor@xxxxxxxx!REMOVE> wrote in message
news:O%23e89RrnGHA.4952@xxxxxxxxxxxxxxxxxxxxxxx
Then the only ways you can add code to a header for VFP6, is to build it
the grid on the fly, or to predefine your grid class using code in the
headers. You can change the header class used in the Init of the grid.
Grid Header classes must be definined in .PRGs.
* GridClass.prg
*
* Sample program to demonstrate programmatic class constructs.
*
* Fred Taylor BBMS, Inc.
* 2001/11/09
* 2002/02/20
*
* Form
LOCAL oForm AS MyForm
oForm = CREATEOBJECT("MyForm")
oForm.Show(1)
* end of executed code
* Class Definitions
DEFINE CLASS MyForm AS Form
AutoCenter = .t.
Caption = "My Programmatic Form Class for a Grid"
DataSession = 2 && Private DS
ADD OBJECT grdData AS MyGrid && Add a MyGrid object
ADD OBJECT lblExitInfo AS Label WITH ;
AutoSize = .t., ;
Caption = "Use the 'X' in the upper right to Exit form", ;
FontBold = .t., ;
Left = 10, ;
Top = 2
FUNCTION Load
* Temp data for the grid
CREATE CURSOR somedata (Field1 L, Field2 C(10), Field3 N(6,2))
INSERT INTO somedata VALUES (.t.,"Data1",55.2)
INSERT INTO somedata VALUES (.f.,"Data2",95.0)
INSERT INTO somedata VALUES (.f.,"Data3",81.7)
GO TOP
ENDFUNC
ENDDEFINE
DEFINE CLASS MyGrid AS Grid
ADD OBJECT col1 AS MyCheckColumn && Add first column (W/checkbox)
ADD OBJECT col2 AS MyColumn && Add second column
ADD OBJECT col3 AS MyColumn && Add second column
FUNCTION Init
this.Left = (thisform.Width-this.Width) / 2
this.Top = (thisform.Height-this.Height) / 2
WITH this.col1
.Sparse = .f.
.Width = 40
.Header1.Caption = "Check"
ENDWITH
WITH this.col3
.Sparse = .f. && Show all special formatting for
this column
.Header1.Caption = "Percent" && Change caption
.Text1.InputMask = "999.99%" && Format as percentage
ENDWITH
ENDFUNC
ENDDEFINE
DEFINE CLASS MyColumn AS Column
ADD OBJECT Header1 AS MyHeader && Columns contain headers
ADD OBJECT Text1 AS MyTextBox && and some other type of input
control
ENDDEFINE
DEFINE CLASS MyCheckColumn AS Column
ADD OBJECT Header1 AS MyHeader && Columns contain headers
ADD OBJECT Check1 AS MyCheckBox && and some other type of input
control
ENDDEFINE
DEFINE CLASS MyHeader AS Header && Custom header class for MyGrid
Caption = "Whatever"
FontName = "Comic Sans MS"
FUNCTION DblCLick
WAIT WINDOW "MyHeader (column "+this.Parent.Name+") double-clicked!"
TIMEOUT 2
this.FontBold = NOT this.FontBold && Toggle boldness
ENDFUNC
ENDDEFINE
DEFINE CLASS MyTextBox AS TextBox && Custom Textbox class for
MyGrid
BorderStyle = 0
Margin = 0
FUNCTION Click
WAIT WINDOW "MyText box clicked!" TIMEOUT 1
ENDFUNC
ENDDEFINE
DEFINE CLASS MyCheckBox AS CheckBox && Custom Checkbox class for
MyGrid
Caption = ""
FUNCTION Click
** WAIT WINDOW "MyCheck box clicked!" TIMEOUT 1
ENDFUNC
ENDDEFINE
--
Fred
Microsoft Visual FoxPro MVP
"Dorian C. Chalom" <DChalom@xxxxxxxxxxx> wrote in message
news:O823O8qnGHA.1664@xxxxxxxxxxxxxxxxxxxxxxx
However I am using VFP 6.0. Sorry should of told you that.
"AA" <A@A> wrote in message news:OVUkIFinGHA.1444@xxxxxxxxxxxxxxxxxxxxxxx
FOR EACH oCol in thisform.grid1.columns
BINDEVENT(oCol.Header1,'Click',thisform,'myUDF')
NEXT
Function myUDF
LOCAL n, oHeader, oColumn, oGrid, lcEvent
n=AEVENTS(aa,0)
oHeader=aa(1)
oColumn=oHeader.Parent
oGrid.oColumn.Parent
lcEvent=aa(2)
Messagebox(oHeader.Caption+ CHR(13)+oHeader.ControlSource)
EndFunc
-Anders
"Dorian C. Chalom" <DChalom@xxxxxxxxxxx> skrev i meddelandet
news:ubfwP7fnGHA.1444@xxxxxxxxxxxxxxxxxxxxxxx
I have a grid in my application and i want to code an action on a click
of the header. And instead of coding the action for each column,
especially since the grid may need to be recreated while runnig the
application I would
like to set the "CurrentControl" of the Header item to a class item I
create.
"Carsten Bonde" <bonde AT real-inkasso DOT de> wrote in message
news:Oo%23rPxAnGHA.4636@xxxxxxxxxxxxxxxxxxxxxxx
Dorian,
do you mean at runtime or designtime?
At design-time take a look at the builders, and how to make your own.
At runtime, you cant add code to anything. If you are building a grid
at runtime, and you want to catch the "Click"-event from the header,
there are (at least) two ways to achieve that.
1. EventBinding.
After creating the grid, do something like that:
FOR EACH loColumn IN THISFORM.Grid.Columns
BindEvent( loColumn.Header1, "Click", THISFORM, "SortList" )
ENDFOR
In the "SortList"-Method you can use AEvents() to determine which
header triggerd the method (event)
METHOD SortList
AEvents( laEvent, 0 )
loHeader= laEvent[1]
messagebox( loHeader.Name +" - " + loHeader[1].Parent.Name )
2. Defining your own header-class
DEFINE CLASS clsMyHeader
PROCEDURE Click
THISFORM.SortList( THIS )
ENDPROC
ENDDEFINE
--
Cheers
Carsten
_______________________________
"Dorian C. Chalom" <DChalom@xxxxxxxxxxx> schrieb im Newsbeitrag
news:O0c2s2%23mGHA.4216@xxxxxxxxxxxxxxxxxxxxxxx
How do i programatically add code to a columns header?
.
- Follow-Ups:
- Re: Grid Column Header
- From: Fred Taylor
- Re: Grid Column Header
- References:
- Re: Grid Column Header
- From: Dorian C. Chalom
- Re: Grid Column Header
- From: Dorian C. Chalom
- Re: Grid Column Header
- From: Fred Taylor
- Re: Grid Column Header
- Prev by Date: Re: Grid Column Header
- Next by Date: Re: Grid Column Header
- Previous by thread: Re: Grid Column Header
- Next by thread: Re: Grid Column Header
- Index(es):
Relevant Pages
|