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!

how to change/split setfocus between class and form

Status
Not open for further replies.

citakumedia

Programmer
Feb 18, 2014
4
i have project1 with form1 and class grid in the class libraries.

form1 including texbox1, textbox2 and textbox3. tab order in the form1 starting from textbox1, textbox2 and textbox3.

in the textbox2 has code which is calling class grid in the class libraries like this:
textbox2 procedure interactivechange
If Empty(This.Value)
With Thisform.Grid1
.Visible=.F.
Endwith
RETURN
Endif

SELECT * From cData Where Upper(Alltrim(This.Value))$;
UPPER(Alltrim(cNama))+Upper(Alltrim(cAlamat));
INTO Cursor cDataku

With Thisform.Grid1
.Visible=.T.
.oTable='cDataku'
.oName=this.Name
.oField="ALLTRIM(cAlamat)"
.RecordSourceType=1
.RecordSource='cDataku'
.Column1.Width=100
.Column2.Width=200
.Column3.Width=100
Endwith
RETURN

in the class grid procedure keypress
LPARAMETERS nKeyCode, nShiftAltCtrl
IF nKeyCode=13
lcTable=ALLTRIM(this.otable)
lcNama=ALLTRIM(this.oName)
lcField=this.ofield

SELECT &lcTable
thisform.&lcNama..value=&lcField
this.visible= .F.

ELSE
IF nKeyCode=7
lcNama=ALLTRIM(this.oName)
thisform.&lcNama..value=''
this.Visible= .F.
ENDIF
ENDIF

the problem is how to set the focus after pick the value from the class grid with use doubleclick or enter and directly change the focus to setfocus to the textbox3 in the form1?



 
To set focus to some control, you do control.setfocus(), so eg after This.visbile = .f. put the line Thisform.textbox3.setfocus()

There is no keycode for doubleclick, but a doubleclick will trigger the dblclick() event of the grid's column control. You need code there, eg in all three grid1.column1.text1, grid1.column2.text1 and grid1.column3.text1. It depends on your VFP version, if you can use bindevent() to bind these three events to one central method of the grid, which you define to react to a doubleclick anywhere in the grid. This is only possible in VFP9.

Handling of doubleclick is easier to do in a listbox than in a grid, as the listbox interactivechange() is triggered by a double click. A grid has no interactivechange or a valid event or a single value property, it also has no incrementalsearch property. All this missing properties and events in general mean, the grid is not a control meant for what you use it for, it's not an editing or picking control, it's meant to display data, only. I can understand, that you want to use it for some advantages, as the headers captions you don't have in a listbox. It's not wrong in that sense, but as it's not meant for picking what you want to do with it is harder to implement.

I hope that helps a bit, already.

Bye, Olaf.
 
thanks olaf for your attention,

i am using VPF9 to this project.

textbox2 as incremental search to get value like supplier_id that user can not remember it. so textbox2 calling class grid to pick value to fill texbox2.

we cannot put Thisform.textbox3.setfocus() cause the focus is in the class grid not in the form1.

so, the problem is how to set the focus after pick the value from the class grid with use doubleclick or enter and directly change the focus to setfocus to the textbox3 in the form1?
 
The grid is showing in a separate form?

Note: A class doesn't necessarily mean the object instanciated from it is a seperate form, so I couldn't know that.

You could change the grid class to be contained in the form, also your code contradicts what you're saying: In textbox2 you address the grid via Thisform.Grid1. If that works, the grid is in the same form as textbox2, so there wouldn't be a problem.

Bye, Olaf.
 
yes, the grid is showing in a separate form.

textbox2 has code to calling class grid

textbox2 procedure init:
SET CLASSLIB TO "E:\pencarian\grdpncarian\grid1.vcx"
Thisform.AddObject('Grid1','barang')
With thisform.Grid1
.Top=This.Top+25
.Left=This.Left
.Visible = .F.
ENDWITH


textbox2 procedure interactivechange
If Empty(This.Value)
With Thisform.Grid1
.Visible=.F.
Endwith
RETURN
Endif

SELECT * From cData Where Upper(Alltrim(This.Value))$;
UPPER(Alltrim(cNama))+Upper(Alltrim(cAlamat));
INTO Cursor cDataku

With Thisform.Grid1
.Visible=.T.
.oTable='cDataku'
.oName=this.Name
.oField="ALLTRIM(cAlamat)"
.RecordSourceType=1
.RecordSource='cDataku'
.Column1.Width=100
.Column2.Width=200
.Column3.Width=100
Endwith
RETURN

the problem still is how to set the focus after pick the value from the class grid with use doubleclick or enter and directly change the focus to setfocus to the textbox3 in the form1?
 
The code you show says the grid is addded to the current form, so there really is no problem referencing textbox3 from the grid.

It doesn't matter, that the grid class is separate, what matter is the objects location at runtime.

SET CLASSLIB TO "E:\pencarian\grdpncarian\grid1.vcx"
Thisform.AddObject('Grid1','barang')

grid.vcx is a separate classlib, still you add the grid to the current form with Thisform.AddObject(), you add an object to this form.

I can understand you won't want to hardcode thisform.textbox3 as the control receiving the focus after the grid is set visible = .f., as you might use the grid in many other forms, too. But there is no simple solution to that problem, if the grid is just added at runtime. It'll have the highest tab order and so setting it invisible will set the focus to the next control, which means the control, and as there is noen with higher taborder, the next control will be the one with taborder 1.

Introduce a property oNextcontrol to the grid class and you can do This.oNextcontrol.Setfocus(), when the focus should be set to the next control you want to have focus. That means you add that property to the class and in creating the grid you set grid.oNextcontrol = Thisform.textbox3

Now there is no event happening, if you set visible = .f. that could be used to do This.oNextcontrol.Setfocus(), but you could add an assign-method visible_assign() and do it there, on condition the value set is .F., then any code hiding the grid would trigger the visible_assign() method and you could set the focus there.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top