Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Grids, columns and methods oh my
Message
From
30/08/2000 05:21:55
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
00410442
Message ID:
00410644
Views:
14
>Hello Everybody
>
>I am re-defining a grid on the fly and I don't know how to define methods within the grid on the fly
>
>I know it is something easy, but the noggin isn't up to par today
>
>Thanks


Stephen,
I don't think it's easy. I think you should elaborate this. The biggest obstacle is runtime code compilation. AFAIK VFP7 will support it.
If you mean how could you create a grid on the fly with different column structure but say same subclassed textbox then I suggest define your grid in a prg. It's easier to control a grid class in a prg. Then you could use addcolumn() to add your custom columns. Sample :
*mytest.prg
DEFINE class myGrid as grid
  DeleteMark = .F.
  ReadOnly = .T.
  RecordMark = .F.
  ScrollBars = 2
  Name = "grdMyGrid"

  PROCEDURE addcolumn
  LPARAMETERS nIndex, cAlias, cField
  NODEFAULT
  this.addobject("clm"+cField,"myColumn", cAlias+"."+cField,nIndex)
ENDPROC

  PROCEDURE init
  LPARAMETERS tcRecordsource
  WITH this
    .Columncount = -1
    .recordsource = tcRecordsource
    nOldColCount = .columncount
    FOR ix = 1 to fcount(tcRecordsource)
      .AddColumn(ix, tcRecordsource,field(ix,tcRecordsource))
    ENDFOR
    FOR ix = nOldColCount to 1 step -1
      .RemoveObject(.Columns(ix).name)
    ENDFOR
  ENDWITH
ENDPROC
ENDDEFINE

DEFINE class myColumn as column
  Resizable = .F.
  Movable = .F.
  PROCEDURE init
  LPARAMETERS cControlSource, nIndex
  WITH this
    .controlsource = cControlSource
    .ColumnOrder = nIndex
    .RemoveObject('Header1')
    .Addobject('myHeader','myHeader')
    .AddObject("myText","myGridTxtBox")
    .CurrentControl = "myText"
    .Sparse = .F.
  ENDWITH
ENDPROC
  PROCEDURE MouseMove
  LPARAMETERS nButton, nShift, nXCoord, nYCoord
  WITH this.Parent
    lnActiveRow = ceiling( ;
      ( nYCoord - (.top + .headerheight) ) / .rowheight )
    .ActivateCell(lnActiveRow,3)
  ENDWITH
  this.setfocus()
  this.myText.Tooltiptext = iif(type(this.controlsource)='C',this.myText.Value,'')

ENDPROC
ENDDEFINE


DEFINE class myGridTxtBox as TextBox
  BackColor = rgb(0,0,255)
  ForeColor = rgb(255,255,255)
  SelectedBackColor = rgb(255,0,0)
  SelectedForeColor = rgb(255,255,0)
  Name = "Text1"
  PROCEDURE init
  this.BorderStyle = 0
ENDPROC
  PROCEDURE click
  this.setfocus()
ENDPROC
ENDDEFINE

DEFINE class myHeader as Header
  BackColor = 0
  ForeColor = rgb(255,255,0)
  PROCEDURE init
  this.Caption = this.parent.controlsource
ENDPROC
ENDDEFINE
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform