CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1
    Join Date
    Aug 2009
    Posts
    19

    Refreshing a form

    right now i have a form that creates an instance of anouther form
    (
    form1 form1instance = new form1();
    form1instance.showdialog()
    )
    the user makes changes in form1instance, and then exits the form.
    how can i refresh the parent form?

    using .net 3.5

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Refreshing a form

    Why do you need to repaint the parent form? What changes that necessitates a repaint?

    To answer your question directly, just call Invalidate() on your parent form, i.e.,

    Code:
    using ( Form1 child = new Form1( ) )
    {
        child.ShowDialog( );
        this.Invalidate( );
    }
    BTW, you are never disposing of your child form, that is why I wrapped it in a using statement.

  3. #3
    Join Date
    Aug 2009
    Posts
    19

    Re: Refreshing a form

    to explain, there is a table in the parent form, and one of the options that i am giving the user is the ability to add, edit and delete rows.
    after the changes are made, and the form is close, no changes will be made to the parent form (i.e. it will still show the rows as the were, not as they are post edit)
    what does this.invalidate do?

  4. #4
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Refreshing a form

    Well, the grid should update when you add the new rows in. I have a feeling that you are adding the rows to the control in your child form and expecting them to appear in your main form. That will not work, they are two different controls. You should probably make a new form class for adding the data and then make that data a property which can be read by the mainform when the child closes.

    Invalidate() forces a repaint of a control. That is not what you need here.

  5. #5
    Join Date
    Aug 2009
    Posts
    19

    Re: Refreshing a form

    no, i am adding the data to the underlying source of the table.
    in this case, the table is drawn from a database, and the user can add edit and delete records.
    i want those changes to appear in the parent.

  6. #6
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Refreshing a form

    Ahhh, ok. I have never actually used bound data sources like that, so perhaps you should post your code and let one of the other members chime in.

  7. #7
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Refreshing a form

    Quote Originally Posted by soandos View Post
    no, i am adding the data to the underlying source of the table.
    in this case, the table is drawn from a database, and the user can add edit and delete records.
    i want those changes to appear in the parent.
    Ok
    at first as I see other threads with similar problems from you:
    1) Is your adding data to the table really working ?
    That means when you add some data can you see them occuring in the databasetable or re they not to be seen there
    2) Have you debugged if the data are really added to the table ?
    because if your datagrid in the maiform is bound to that table and your table is really updated so using the debugger you can see them existing in the databale and they are also stored in the database then you need to look how your datagrid is bound to the table, because it normally should update automatically otherwise simple try to refresh your Datagridview.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  8. #8
    Join Date
    Aug 2009
    Posts
    19

    Re: Refreshing a form

    No, the data gets written properly, just the previous form does not refresh.
    Last edited by soandos; September 6th, 2009 at 09:08 PM. Reason: forgot witch post i was on

  9. #9
    Join Date
    Aug 2009
    Posts
    19

    Re: Refreshing a form

    Would adding
    Code:
    this.Refresh();
    to the focus activated event fix this problem?
    or do i add it to the focus enter event.
    Last edited by soandos; September 6th, 2009 at 09:17 PM. Reason: addition

  10. #10
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    460

    Re: Refreshing a form

    Just try it adding and see if it worked or not.

  11. #11
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Refreshing a form

    Quote Originally Posted by soandos View Post
    No, the data gets written properly, just the previous form does not refresh.
    OK in which way is it connected to the DataSet or DataTable , or if you cannot find out zip a testdatabase and the project and show it. (For zipping the project delete data in BIN and OBJECT files then zip the project
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  12. #12
    Join Date
    Aug 2009
    Posts
    19

    Re: Refreshing a form

    by a databinding

  13. #13
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Refreshing a form

    Quote Originally Posted by soandos View Post
    by a databinding
    Yea sure, but IMHO you need to post code as this sounds strange.Normally that would work
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  14. #14
    Join Date
    Aug 2009
    Posts
    19

    Re: Refreshing a form

    disregard case (the select mode is for the whole row in the Datagirdviewer):
    Code:
    string s = DGVS.SelectedRows[0].Cells["ID"].Value.ToString();
    form1 form1instance = new form1();
    form1instance.s = s;
    form1instance.showdialog();
    in form1 i edit some of the rows, and then close the form with:
    Code:
    this.close();
    the first form will not update automatically

  15. #15
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Refreshing a form

    Quote Originally Posted by soandos View Post
    disregard case (the select mode is for the whole row in the Datagirdviewer):
    Code:
    string s = DGVS.SelectedRows[0].Cells["ID"].Value.ToString();
    form1 form1instance = new form1();
    form1instance.s = s;
    form1instance.showdialog();
    in form1 i edit some of the rows, and then close the form with:
    Code:
    this.close();
    the first form will not update automatically
    Sorry this is nothing where I can think with.
    as I still cannot see any code how th Datagridview is exacly filled nor where it is updated. You cannot solve your problem without debugging so how should I debug it by this lines of unworkable code
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured