multi forms - form1 not reloading
Hi I am using two forms.
Form 1 organizes student information from a textfile
Form 2 appends a new student
I load the second form with:
Code:
Dim secondForm As New Form2
secondForm.ShowDialog()
It loads, cool..
When I close form 2 with me.close, form 1 does not have the updated information. (Most things load with the form_load event)
Any ideas? This is form my intro to VB course. Thanks :thumb:
Re: multi forms - form1 not reloading
The data won't just appear in Form1. You have to write code to get it form somewhere and display it. Assuming that Form2 saves the data then the simplest option is to simply move the code that loads the data out of the Load event handler and into its own method. You can then call that method from the Load event handler and any other time it's needed too.
A better option, in my opinion, is for Form2 not to save the data. Once Form2 is dismissed, Form1 retrieves all the new data from Form2 via properties that you have declared. Form1 will then add that data to the data its displaying and then Form1 will save the changes. That way Form1 is responsible for all data management and Form2 is just a data entry form.
Re: multi forms - form1 not reloading
jmcilhinney--I entirely agree with you about the second point, that I should store all the info using Form 1. Unfortunately I do not think I have enough time to recode it...This is my first experience with multi forms.
What code would allow me to reload it? edit: (... I have no idea how to do what you said)
Re: multi forms - form1 not reloading
Quote:
Originally Posted by
crabramson
I have no idea how to do what you said)
Yes you do because you've done it before, more than once I'm sure. You've declared a Sub before, yes? You've called a Sub before, yes? That's all you've got to do now. Declare a Sub and take the code that loads the data out of the Load event handler and put it in that new Sub. You then call that new Sub in the Load event handler and everything will happen as it did before. Now, though, you can call that same Sub from other places too, whenever you need to load data. You need to load data after your second form is dismissed so you just call your Sub at that point.
Re: multi forms - form1 not reloading
thank you very much sir
it works great now
in the future it would be more helpful if you gave examples of code, but nonetheless you're very helpful indeed
one problem i faced:
it was doubling null fields in the listbox when I generated the student report so i added an if statement to check for null before output
Re: multi forms - form1 not reloading
Quote:
Originally Posted by
crabramson
in the future it would be more helpful if you gave examples of code
That depends on your definition of helpful. It might make it easier for you if I provided the code for you but I don't post here to make it easy for people. I post to help people become better developers and I find that the best way to do that is to push people to think for themselves because that's how you learn. As has been born out by the result, you actually did already know how to solve your own problem so you didn't need me to write the code for you. If I can make people think first and ask questions later instead of having other people do their thinking for them as a first option then I've been as helpful as I possibly can. You'll thank me in years to come. ;)
Re: multi forms - form1 not reloading
Just out of curiosity, what code could JM have provided that would have been any help? What he described was to add a sub and copy and paste existing code. I'm kind of curious as to what a meaningful code example would look like? If you meant an example of using properties, there is one that I could post a link for, but I don't think there was all that much code in that thread, either, as there is very little 'example' possible.