Solved

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

Posted on 2006-11-10
4
191 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

762 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