Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to Add/Remove colums from grids
Message
De
22/09/2000 12:05:48
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
22/09/2000 09:36:46
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
00419681
Message ID:
00419795
Vues:
19
>I have a grid from which I need to add or remove columns on a regular basis at runtime.
>
>I have experimented with the width and visible properties for the columns but I am unhappy with the results.
>
>RemoveObject works well but then I have the problem of putting the column back when I need it.
>
>If use addobject then it appears I have to specify all the properties and methods for the column in code before I add it back.
>
>Is there a way I can store the properties and methods of an existing column to a class, then remove the column....and later add it back from that class?
>
>Or is there a much better way of doing this job that I have missed, as is still often the case:(
>
>I expect someone will point out that there is a HideColumn property somewhere that I have missed :(
>
>Thanks in advance


Hiding columns is not a good solution most of the time instead use Addcolumn, RemoveColumn methods of grid itself. Column class is not available to be visually designed but you can do it in code. Also you can subclass header in code or visually design in an existing grid and saveasclass (VFP6 supports). Here is a sample that would create a fancy grid :)
*gridonthefly.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
Calling sample :
create a form with a commandbutton, add employee to DE.
*Commandbutton.click
set procedure to gridonthefly.prg additive
thisform.Addobject('myGrid','myGrid','Employee')
with thisform.myGrid
 .Height = this.top
 .Width = thisform.width 
 .Visible = .t.
endwith
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform