UserControl how do I get the code in Load event run again when user control gets focus
Posted on 2006-11-10
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.