Click to See Complete Forum and Search --> : Refreshing a form


soandos
September 3rd, 2009, 01:33 PM
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

BigEd781
September 3rd, 2009, 01:39 PM
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.,


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.

soandos
September 3rd, 2009, 01:47 PM
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?

BigEd781
September 3rd, 2009, 02:04 PM
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.

soandos
September 3rd, 2009, 02:11 PM
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.

BigEd781
September 3rd, 2009, 02:44 PM
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.

JonnyPoet
September 6th, 2009, 04:21 PM
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.

soandos
September 6th, 2009, 09:02 PM
No, the data gets written properly, just the previous form does not refresh.

soandos
September 6th, 2009, 09:12 PM
Would adding

this.Refresh();


to the focus activated event fix this problem?
or do i add it to the focus enter event.

vcdebugger
September 7th, 2009, 12:48 AM
Just try it adding and see if it worked or not.

JonnyPoet
September 7th, 2009, 02:11 AM
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

soandos
September 7th, 2009, 11:42 AM
by a databinding

JonnyPoet
September 7th, 2009, 02:39 PM
by a databindingYea sure, but IMHO you need to post code as this sounds strange.Normally that would work

soandos
September 7th, 2009, 09:55 PM
disregard case (the select mode is for the whole row in the Datagirdviewer):

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:

this.close();

the first form will not update automatically

JonnyPoet
September 8th, 2009, 05:03 AM
disregard case (the select mode is for the whole row in the Datagirdviewer):

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:

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