rpp


Does the Init() procedure of a form, fire before the Load() procedure of the form.

I am trying to use a SQL Select in the Load() of a form with a passed form property from a ComboList box [a value set within it's Init()]. I had hoped to initialize the passed property before the Forms Load() event and its SELECT-SQL ran, then optionally let the user select different values in the ComboList box and then have it call the Load() event when the user changes the selection.

I am not sure of the event firing sequence.

Thanks in Advance

Richard




Re: What fires first Init() or Load()

Alex Feldstein


Load() fires first.

The order is remembered by the mnemonic: LISAG

L - Load

I - Init
S - Show
A - Activate
G - GotFocus






Re: What fires first Init() or Load()

Naomi Nosonovsky

You would have to initialize your combobox programmatically in the Init method of your form. Leave RowSource and RowSourceType empty in design time and set them in run-time once you have your parameter in the form's Init.






Re: What fires first Init() or Load()

Christof Wollenhaupt

Instead of calling the Load event from the combobox when the selection changes, you should create a new method on the form and call this method from the Init event of the form and the InteractiveChange event of the combobox.

Why do you need to execute the query in the Load event If the reason is a problem with the RowSource or a ControlSource, you can use the BindControls property of the form. Set it to .F. in the designer and programmatically to .T. in the form's Init after you executed the query.





Re: What fires first Init() or Load()

rpp

The selection in the combobox changes the contents of a grid on the form. I had hoped to populate the grid upon opening the form, and then let the user change the combobox list to change/filter the contents in the grid using a SQL-Select.

I had thought it was good practice to have all tables open from within the Load event. I can make a separte SQL method as you mentioned and call it from the init event o fthe form and the InteractivChange event. That way I have only 1 statement populating the grid.

Does that sound like normal practice





Re: What fires first Init() or Load()

Naomi Nosonovsky

Yes, sounds good as a separate method to refresh the grid.





Re: What fires first Init() or Load()

rpp

Ok, I believe understand except for one thing. The Grid in which I set up programatically, with ControlSource's for each field to be shown, does not refresh once I change the value in my ComboBox. It works when I first load the form, but when I select another value in the ComboBox the grid goes empty.

I have tried to clear the connection to the grid from the table, but it has not worked

This is my Select Method I have created that was to repopulate the grid on the form when the user changed a value in the ComboBox.

What have missed It's as if once the grid is initilized it cannot be updated.

***********************************************
* GET THE DATA FOR THE FORM
***********************************************
IF USED('cAdtype')
USE IN cAdtype
Thisform.grdadtype.recordsource = " "
Thisform.grdadtype.recordsourcetype = 0 &&Table
ENDIF

SELECT ALL * ;
FROM adtype ;
WHERE adtype.booktype = Thisform.booktype ;
INTO CURSOR cAdtype

***********************************************
* GET THE GRID READY FOR THE FORM
***********************************************
Thisform.grdadtype.recordsource = "cAdtype"
Thisform.grdadtype.recordsourcetype = 1 &&ALIAS

Thisform.grdadtype.columncount = 4
Thisform.grdadtype.deletemark = .f.
Thisform.grdadtype.gridlines = 2 &&vertical only

Thisform.grdadtype.Column1.ControlSource = 'adtype'
Thisform.grdadtype.Column1.Header1.Caption = 'Adtype'
Thisform.grdadtype.Column1.Readonly = .T.

Thisform.grdadtype.Column2.ControlSource = 'description'
Thisform.grdadtype.Column2.Header1.Caption = 'Description'

Thisform.grdadtype.Column3.ControlSource = 'rate'
Thisform.grdadtype.Column3.Header1.Caption = 'Rate'
Thisform.grdadtype.Column3.SetAll("DynamicInputMask", "@l$ ###,###,###.##")

Thisform.grdadtype.Column4.ControlSource = 'priority'
Thisform.grdadtype.Column4.Header1.Caption = 'Priority'

Thisform.grdadtype.column1.width = (Thisform.grdadtype.width * .20)
Thisform.grdadtype.column2.width = (Thisform.grdadtype.width * .50)
Thisform.grdadtype.column3.width = (Thisform.grdadtype.width * .12)
Thisform.grdadtype.column4.width = (Thisform.grdadtype.width * .10)






Re: What fires first Init() or Load()

Naomi Nosonovsky

Right before running your select put

thisform.grdAdType = ""

However, I prefer to use a different technique, called 'safe select'. It was discussed here recently few times.

See http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=346475&SiteID=1 and http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1688378&SiteID=1 for example.





Re: What fires first Init() or Load()

MarciaAkins

rpp wrote:

The Grid in which I set up programatically, with ControlSource's for each field to be shown, does not refresh once I change the value in my ComboBox. It works when I first load the form, but when I select another value in the ComboBox the grid goes empty.

You can do this much more easily by creating the CURSOR that you are using for the grid's RecordSource in the form's Load() method using the CREATE CURSOR command. Then you can set up your grid visually in the form designer. Since the form's Load() method fires before the grid's Init(), the cursor will be available for the grid to bind to when it is instantiated.

Then in the valid method of your combo box and from the form's Init() you can call a method that resets the contents of the grid using a technique that my husband and I like to call a safe select (As a matter of fact, it was Hue Holleran, a former lead deveoper of Andy's at FoxWare UK, who originally coined the phrase back in 1996). You can find a complete and detailed explanation of this technique at http://weblogs.foxite.com/andykramek/archive/2005/03/19/174.aspx