locked
thisform.refresh not clearing the text field RRS feed

  • Question

  • Hi Everyone!!

    I'm a new one to VPF 8.0 and am trying to display a form in which a grid showing the db data and below the gird their will be three textfield where i can add details and if i click save it will be added to the grid as well as in db. everything is working fine , but i also have a button called NEW next to SAVE,but when i click the new btn the text fields should be cleared so that i can enter a new fields and can save it, but its not working ..

    The code  I gave on dblclick of new btn is

    thisform.refresh or thisform.text1.refresh

    Please kindly help me...




    • Edited by Sowndarya S Monday, January 13, 2020 5:52 AM
    Monday, January 13, 2020 5:10 AM

All replies

  • Hi Sowndarya,

    welcome to the forum and VFP :)

    .Refresh doesn't init the value of any object on a form. It just takes care, that every object displays its real current value. Therefore, doing a refresh to 'clear' the content of an object can't work.

    So, let's have a look on how you describe your forms functionality:

    You have a grid that displays some table content. This seems to work properly.

    You have some textboxes for adding data to the grid and therefore to the table. This seems to be working, too.

    Now it would be nice to know, how exactly you are adding the data from the textboxes.

    Usually, those textboxes are bound to the grids current record by defining their .controlsource property like 'myTable.mycolum'. Then, by clicking on the 'NEW' button, all you would need to do is adding a new empty record, placing the recordmarke on this new (an last) record in the table (GO BOTTOM) and the textboxes would be cleared automatically. You don't even need a 'SAVE' Button in this case.

    NEW and SAVE are only needed, when there are no assigned controlsources for your textboxes.

    In this case, you will have to initiate their values on your own. All you need is to know what kind of data in each textbox is kept (integer, character, date, a.s.o.). Then you assign 'EMPTY' values to the textboxes. So, assuming that you placed the object directly on the form and box1 is an integer, box2 a char and box 3 a date you would place the following code in a method i.e. called 'init_textboxes' or (if you haven't found out yet, how to add methods to a form at designtime) put it in the click event of your NEW button:

    Thisform.Textbox1.Value = 0 Thisform.Textbox2.Value = "" Thisform.Textbox3.Value = {..}

    Thisform.Refresh

    HTH


    Gruss / Best regards
    -Tom
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible,
    you are, by definition, not smart enough to debug it. 010101100100011001010000011110000101001001101111011000110110101101110011

    Monday, January 13, 2020 6:11 AM
    Answerer
  • Thanks for the quick reply!

    I got your content, yes i don't even need a SAVE btn since i have bind the textbox with the control source like what you mentioned above.

    My functionality is I have a grid above which displays all the records form the db.When I double click on any of the row ,It will display the details in the below textboxes of that particular row.

    So if I give like Thisform.Textbox2.Value="" in my new btn click, and when i click new btn after clicking on any of the row from the grid,

    existing details become null.

    what should i do now?


    • Edited by Sowndarya S Monday, January 13, 2020 6:26 AM
    Monday, January 13, 2020 6:26 AM
  • one thing in advance: a single click in one of the grid rowse already changes the record and therefore will change the values in the texdtboxes, already.

    And don't use DBLCLICKs on commandbuttons. Buttons have to react on a single click.

    Now to your question...

    This depends on what you want to accomplish....

    1. creating a new empty record (usually what a NEW button should do)

    you have to create a new record (-> have a look at 'APPEND BLANK' in help file)

    and position the record mark on this new record (-> have a look at the GO command in help file)

    2. initiating data in current record (usually what a INIT button should do)

    in such a case, you have to REPLACE the current records values with empty values. This can be done with the REPLACE command. This will empty the column contents and therefore the textboxes that are bound by .controlsource property.

    BTW: A good source for learning the basics are the Videos you can find here:

    https://www.garfieldhudson.com/FreeVideos.aspx

    It will help you a lot to understand how VFP works.


    Gruss / Best regards
    -Tom
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible,
    you are, by definition, not smart enough to debug it. 010101100100011001010000011110000101001001101111011000110110101101110011


    Monday, January 13, 2020 7:54 AM
    Answerer
  • Thanks a lot Tom,..

    Indeed a great help.

    Monday, January 13, 2020 8:29 AM