Solved

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

Posted on 2006-11-10
4
193 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

635 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