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!

How to initialize values on form

Status
Not open for further replies.

alisaif

ISP
Apr 6, 2013
418
AE
Hi,

Please refer to the image, is it possible to clear all the values with some command rather than to initialize one by one like;
I want to clear that after displaying records.

Code:
This.parent.Grid1.RecordSource = ''
This.parent.CboLock.DisplayValue = ''
This.parent.cboTitle.DisplayValue = ''
This.parent.mCr_limit.Value = 0
This.parent.mFax.Value = ''
This.parent.mMobile.Value = ''
This.parent.mName.Value = ''
This.parent.mPcode.Value = ''
This.parent.mPerson.Value = ''
This.parent.mPterms.Value = 0
This.parent.mTel1.Value = ''
This.parent.mTel2.Value = ''
This.parent.mTel3.Value = ''

Thanks

Saif
variable_a93uyg.jpg
 
You could try something like this:

[tt]this.Parent.SetAll("value", "")[/tt]

But it's not quite what you want. It will set all values to an empty character string, whereas you might want numeric values set to zero, logical values to .F., etc. Also, it assumes that you want to clear the values of all the controls, not just the ones you specify.

A better option might be something like this:

Code:
WITH THISFORM
  STORE "" TO ;
    .Grid1.RecordSource, .CboLock.DisplayValue, .mFax.Value, ;
    [i]etc. etc.[/i]

  STORE 0 TO ;
    .mCr_limit.Value, .mPterms.Value, ;
    [i]etc. etc.[/i]
ENDWITH

Still not ideal, but possibly a good starting point.

If the various controls are bound to fieds in a table or cursor, simply doing APPEND BLANK will have the desired effect.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks Mr.Mike,

It is nice and working fine!

Saif
 
Yopu better have control classes, in which you could add a reinit property define a reinit_assign method. [tt]Thisform.SetAll("reinit",.T.)[/tt] then would trigger the reinit_assign method of any control. And you don't need to define code for any control, as the reinitialisation should mostly only depend on the type of control and type of controlsource. You can write general code acting on this.

Besides that, you normally would simple restart a form itself to get it to reinitialize in whatever way foreseen for that matter, eg DO FORM sameform followed by Thisform.Release(), obviously only working this way with non modal forms.

One specific thing I see makes me think you haven't got a good grip on how the combobox works, you never need to set the DisplayValue, that's automatically adjust once the controlsource and rowsource are set and bound and a velu is set by controlsource or manually to control which row of the rowsource is becoming actively displayed.

Bye, Olaf.
 
Hi Mike,

Glad it's working, Saif. But it would be good to know which of my suggestions you used.

This one,

Code:
WITH THISFORM
  STORE "" TO ;
    .Grid1.RecordSource, .CboLock.DisplayValue, .mFax.Value, ;
    etc. etc.

  STORE 0 TO ;
    .mCr_limit.Value, .mPterms.Value, ;
    etc. etc.
ENDWITH

Thanks

Saif
 
Thanks Olaf,

Nice suggestion, I will try on it.
But,

One specific thing I see makes me think you haven't got a good grip on how the combobox works, you never need to set the DisplayValue, that's automatically adjust once the controlsource and rowsource are set and bound and a velu is set by controlsource or manually to control which row of the rowsource is becoming actively displayed.

I could not get it properly. Can you explain with some example.

Saif
 
DisplayValue is - as the name says, just the displayvalue of the combobox, it's not meant to set it's Value nor controlsource nor Rowsource. In a bound combobox the rowsource determines the list of values, if that's a DBF/cursor alias the current record determines the value and the displayvalue is determined by the first column of the DBF or the first field of the list of fields you may specify in a rowsourcetype 6 ("Fields").

With all these options the Displayvalue is the least important to set, it's set automatic and just depends on current item selected and you should care about that aspect. Setting DisplayValue is not setting current row, so next Refresh() will show the old DisdplayValue.

This is not described in 1 example. There are many ways to use the combobox with DBFs, Cursors, but also with specifying a comma separated list of possible values. Please refer to the samples coming with VFP, Task Pane -> Solution Samples or open up the form in _Samples+"\Solution\Controls\Combobox\lookup.scx".

Besides, read the help topic on the properties I suggested as important already, and you'll get a better grip.

DisplayValue surely is not the property to reset, anyway.

One simple, yet not universal reinitialisation of a combobox is setting its ListIndex=0, so no item is selected.

But more genereally speaking you would have controls bound to controlsources and a reinitialisation should only need to care for the controlsources, not the controls and their properties, they are already bound and are both influencing/modifying the controlsources but also are controlled by the controlsources.

For example if a a textbox is bound to a textfield of a DBF, say persons.lastname the visual effect of txtLastname.Value = "" is the same as APPEND BLANK in the Persons.DBF, but when you set the textbox value, you not only blank the textbox, you also blank the current records persons.lastname, if you APPEND BLANK, you create a new record with empty lastname. That's also a reason I considered restarting the form instead of reiniting it, you have to be careful what you cause with blanking controls, you might act on the data in a way you didn't intended.

Bye, Olaf.
 
In regard to your form, judging by the screenshot The upper header has a line of unbound controls you may blank for reinitialisation, they filter the grid content, most probably. The grid is displaying a table or query result to pick from a list and the lower detail area is with controls bound to single fields for editing. You DON'T reinit this area of controls. You simply do THISFORM.REFRESH() after [tt]GO TOP[/tt] or [tt]LOCATE[/tt] in the grids table.

This form looks as if blanking the controls in the form head area and resetting a FILTER on the grid recordsource will make the grid show all records again, the detail area below the grid showing the current/first row. You don't fiddle with these controls at all, the current row of the grid determines what they display and nothing else.

Edit (after Mike posted, too): You only need to reinit the unbound controls, the bound controls are getting their current correct display value (or value, or picked item, or whatever) from their binding to tables or cursors (views). Look out for a FILTER to reset, just blanking the upper controls doesn't let their InteractiveChannge or Valid or Lostfocus events happen, which most probably influence a FILTER on the grid recordsource or do a SQL query. So even blanking these unbound head controls you don't reset the grid to display all data unfiltered, you most probably need to do something on top, normally triggered by all of the head controls.

So you can stay with the code to blank the head controls, but most probably should for example NOT set mCr_limit.Value, as you thereby really change data, though you only want to refresh the display of the current row.
The core thing to do after you blanked the head controls (i.e. mPCode, mName,.. ,cboTitle, mPerson, cboLock) and reset the grid to display all rows [tt]SELECT (Grid.recordsource)[/tt] followed by [tt]SET FILTER TO[/tt] (no filter), you should call [tt]Thisform.Refresh()[/tt], controls bound to a controlsource will then refresh their display themselves, if you set their value you change data you don't want to change.

Bye, Olaf.
 
Thanks Mr.Olaf/Mike for the nice suggestions. I will definitely look into it.

Saif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top