Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Want to add popup to a grid @ row/col position

Status
Not open for further replies.

JerMyster

IS-IT--Management
Mar 17, 2003
49
US
Have a grid tht works well but want to add a popup to a when a cell is picked. I'd like the popup to show with relitive position to the active cell.

Any ideas ?
 
Where does the popup appear now? If the user selects a cell with the mouse then it should appear at the mouse position.

Sorry - I'm assuming "pop-up menu". Is it a menu or another form that you want to show?

Geoff Franklin
 
Maybe this will help you get started...

Code:
local o
o = createobject("frmOne")
o.show()
read events

*** Form class ***
define class frmOne as form
  docreate = .t.
  autocenter = .t.
  datasession = 2
  height = 342
  width = 486
  borderstyle = 2

  caption = "Grid with context menu (i.e. PopUp)"

  add object grdOne as grdOne with ;
    deletemark = .f., ;
    left = 12, ;
    top = 12, ;
    height = 254, ;
    width = 468


  add object txtOne as textbox with ;
    left = 12, ;
    top = 288, ;
    width = 468

  * protected procedure destroy
  protected procedure destroy
    release popup GridContextPopUp
    clear events
  endproc

  * protected procedure error
  procedure error
    lparameters nError, cMethod, nLine
    local array aErrors[1]
    aerror(aErrors)
    if nError = 1429 .and. aErrors[1,3] == "Procedure canceled."
      return
    endif

    * some other error!
    set step on
  endproc

  * protected procedure load
  protected procedure load
    create cursor testit (field1 c(10), field2 i)
    for i = 1 to 1000
      insert into testit ;
        (field1, field2) values ;
        ("field"+padl(trans(i),5,"0"),rand()*1000)
    next
    go top

define popup GridContextPopUp from 3,20 to 12,35 margin mover scroll title "Help"

for i = 1 to 20
define bar i of GridContextPopUp prompt 'Bar'+padl(trans(i),2,"0")
next

on selection popup GridContextPopUp ;
  _vfp.activeform.popupchoice( ;
  prompt( ), popup( ),_vfp.activeform.activecontrol.value ;
  )

endproc

* Procedure: InvokeContextMenu
  procedure InvokeContextMenu
    move popup GridContextPopUp to mrow(),mcol()
    activate popup GridContextPopUp
  endproc

  * Procedure: PopupChoice
  procedure PopupChoice
    lparam cPrompt, cPop, vValue
    this.txtOne.value = "You've chosen "+cPrompt+;
    " of "+cPop+" with a field value of "+trans(vValue)

    deactivate popup GridContextPopUp
  endproc

enddefine


*** Grid Class ***
define class grdOne as grid

  columncount = -1

  add object column1 as clsCols
  add object column2 as clsCols

  procedure init
    this.column1.header1.caption = "Field1"
    this.column2.header1.caption = "Field2"
  endproc

enddefine


*** Column class ***
define class clsCols as column
  add object txtInvoker as clsInvoker
enddefine


*** Textbox class ***
define class clsInvoker as textbox
  procedure rightclick
    thisform.InvokeContextMenu()
  endproc
enddefine
 
Hello JerMyster.

I'd like the popup to show with relitive position to the active cell.

You did not specify whether this is a popup menu or a popup form. If it is a form that you are instantiating, you want to pass the co-ordinates of the current cell to the form that you are popping up like so:

Code:
*** Calculate where the popup calendar should be instantiated
*** So it pops up directly below the date text box
*** SYSMETRIC( 9 ) is the height of the Form's title bar in case you were curious
lnTop = OBJTOCLIENT( Thisform, 1 ) + OBJTOCLIENT( This, 1 ) + This.Height + ;
              IIF( Thisform.TitleBar = 1, SYSMETRIC( 9 ) + 2, 2 )
lnLeft = OBJTOCLIENT( Thisform, 2 ) + OBJTOCLIENT( This, 2 )

DO FORM Calendar WITH lnTop, lnLeft, This.txtDate.Value TO luValue

This code in the popup form's Init() to position it properly:

Code:
LPARAMETERS tnTop, tnLeft, tdInitialDate

*** Initialize the combo with the passed date
*** Default to today if empty
WITH Thisform
  *** Position it correctly
  .Top = IIF( NOT EMPTY( tnTop ), tnTop, 0 )
  .Left = IIF( NOT EMPTY( tnLeft ), tnLeft, 0 )
ENDWITH


Marcia G. Akins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top