Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

UserControl how do I get the code in Load event run again when user control gets focus

Posted on 2006-11-10
4
Medium Priority
?
197 Views
Last Modified: 2012-05-05
Hi,

I am using VS 2003 .NET 1.1 Winforms

I have a wizard like interface - main form with a panel and several UserControls.  The main form has next, back and finish button just like most other wizards.  Everything worked great so far.  Now, I have added two last UserControls each representing a page in the wizard.  In the first UserControl, 13 dynamically created checkbox with events hooked.  User select the checkboxes they want then click Next button.  When users select a checkbox, I create an object (let us call it Crop) and stick it into a HashTable and when they unselect a checkbox I remove the object from the HashTable.  This is all good.  The next screen displays data for the objects in the HashTable (this is done in UserControl Load event).

The problem ....

If a user selects 1 checkbox and goes to the next screen we see 1 object data, which is correct.  then if user clicks Back button to the previous screen and selects 3 more checkboxes then clicks Next, the next screen displays data for 1 object, the one user selected first time.  This is because, second time when user clicks next, UserControl Load event doesn't fire because the UserControl is already loaded.  I don't want to unload usercontrol everytime as this means I have to persist data, repopulate it into control as well as changing quite a bit of my design.

Is there a way round this?  I tried grapping the Enter event and the GotFocus event, none of them work for me.  all I need to do is call the 2 methods that build the screen when user comes back having changed some data in the previous screen

I hope someone can sus this out.

Thanks
Hassan
 
0
Comment
Question by:gbzhhu
  • 2
  • 2
4 Comments
 
LVL 6

Expert Comment

by:so3
ID: 17918272
Why don't you execute the 2 methods when you press the next button. You know when to show the usercontrol that displays data for the objects in the HashTable, right? so call the methods after you show the usercontrol
0
 
LVL 12

Author Comment

by:gbzhhu
ID: 17926051
so3,

Thanks for your suggestion.  I didn't think of this to be honest but I should have.  Now that you brought it to my attention there is just one issue

1.  UserControl has a set of methods defined and my methods are not one of these, therefore, the workaround is to implement an interface that defines the two methods in the UserControl.  I think I will give this a go.

Thank you.  I will try this tomorrow when I am at work

Hassan
0
 
LVL 6

Accepted Solution

by:
so3 earned 2000 total points
ID: 17928307
I don't think that is need for an interface if you use only one Usercontrol do do the job just make those methods public and you will see them outside the class.
If you use those methods for multiple kinds of Usercontrol then you should use an interface but in your case from what i've understood i don't think that you need it.

so3
0
 
LVL 12

Author Comment

by:gbzhhu
ID: 17928836
I already had the usercontrol implement an interface to communicate with the main form, so i just added the 2 methods and it looks good

Thank you for your help

Hassan
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Loops Section Overview
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question