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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Container in grid 1

Status
Not open for further replies.

raspoutine

Programmer
Sep 28, 2001
13
FR
In the following example, I use a container (Textbox + Buttom) in a grid. When i use the keyboard arrow key to move the cursor up or down in the column with the container(Column 2), the cursor go in the nearest Column.
Is it possible to
How to make for the cursor go up or down in the column with the container ?

oForm = CREATEOBJECT("myForm")
oForm.Height = 400
oForm.Width = 600
oForm.ADDOBJECT("oGrd1","NewGrid")
oForm.oGrd1.Top = 20
oForm.oGrd1.Left = 5
oForm.oGrd1.Width = 550
oForm.oGrd1.Height = 300
oForm.oGrd1.Columncount = 4

WITH oForm.oGrd1.Column1
.Addobject("MyTxt","NewTxt1")
.Width = 70
.CurrentControl = "MyTxt"
.Controlsource = "myCursor.Name"
.Sparse = .T.
.Visible = .T.
ENDWITH

WITH oForm.oGrd1.Column2
.Addobject("MyCnt","NewCnt1")
.Width = 160
.CurrentControl = "MyCnt"
.Sparse = .F.
.Visible = .T.
ENDWITH

WITH oForm.oGrd1.Column3
.Addobject("MyTxt","NewTxt1")
.Width = 70
.CurrentControl = "MyTxt"
.Sparse = .T.
.Controlsource = "myCursor.Phone"
.Visible = .T.
ENDWITH

WITH oForm.oGrd1.Column4
.Addobject("MyTxt","NewTxt1")
.Width = 60
.CurrentControl = "MyTxt"
.Sparse = .T.
.Controlsource = "myCursor.Qty"
.Visible = .T.
ENDWITH



oForm.SHOW(1)
DEFINE CLASS myForm AS FORM
PROCEDURE LOAD
CREATE CURSOR mycursor (NAME c(10),Num c(10),Phone C(10),QTY c(10))
INSERT INTO mycursor (NAME,Num,Phone,Qty) VALUES ("Bill","00725","555 1212","125")
INSERT INTO mycursor (NAME,Num,Phone,Qty) VALUES ("Mikel","00728","555 1232","25")
INSERT INTO mycursor (NAME,Num,Phone,Qty) VALUES ("Jan","00729","555 5432","13")
INSERT INTO mycursor (NAME,Num,Phone,Qty) VALUES ("Rosa","00730","555 5555","177")
INSERT INTO mycursor (NAME,Num,Phone,Qty) VALUES ("John","00735","666 6666","250")
INSERT INTO mycursor (NAME,Num,Phone,Qty) VALUES ("Henry","00742","777 7777","60")
GO TOP
ENDPROC
ENDDEFINE


DEFINE CLASS NewGrid AS GRID
COLUMNCOUNT = 3
VISIBLE = .T.
ROWHEIGHT = 40
Width = 600
height = 500
ENDDEFINE



DEFINE CLASS NewTxt1 as TextBox
HEIGHT = 23
WIDTH = 80
NAME = "NewTxt1"
ENDDEFINE


DEFINE CLASS NewCnt1 AS CONTAINER
VISIBLE = .T.
WIDTH = 150
HEIGHT = 30
NAME = "NewCnt1"

ADD OBJECT Text1 AS TEXTBOX WITH ;
HEIGHT = 23, ;
LEFT = 12, ;
TOP = 5, ;
WIDTH = 80, ;
NAME = "Text1",;
Tabindex = 1, ;
CONTROLSOURCE="myCursor.Num"

ADD OBJECT Bout1 AS COMMANDBUTTON WITH ;
HEIGHT = 23, ;
LEFT = 90, ;
TOP = 5, ;
WIDTH = 23, ;
NAME = "Bout1", ;
Tabindex = 2, ;
Tabstop = .F., ;
VISIBLE = .T.

PROCEDURE text1.keypress(nKeyCode, nShiftAltCtrl)
IF nKeyCode = 24
SKIP 1 IN "myCursor"
IF EOF()
GO BOTTOM
ENDIF
DODEFAULT( )
this.Parent.Parent.parent.refresh()
this.Parent.text1.setfocus()
ENDIF
IF nKeycode = 5
SKIP -1 IN "myCursor"
IF BOF()
GO TOP
ENDIF
this.Parent.Parent.parent.refresh()
this.Parent.text1.setfocus()
ENDIF
ENDPROC

PROCEDURE BOUT1.CLICK
MESSAGEBOX("Hello")
ENDPROC

ENDDEFINE
 
Change this:

Code:
  PROCEDURE text1.keypress(nKeyCode, nShiftAltCtrl)
     IF nKeyCode = 24
        NODEFAULT 
        SKIP 1 IN "myCursor"
        IF EOF()
           GO BOTTOM
        ENDIF
        this.Parent.Parent.parent.refresh()
        this.Parent.text1.setfocus()
     ENDIF
     IF nKeycode = 5
        NODEFAULT 
        SKIP -1 IN "myCursor"
        IF BOF()
           GO TOP
        ENDIF
        this.Parent.Parent.parent.refresh()
        this.Parent.text1.setfocus()
     ENDIF
  ENDPROC

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top