Solved

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

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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
need to convert function to c# 5 55
Problem to Office 1 67
C# Windows Form Navigation - Total Beginner 9 93
C# Get Current Exchange Rate from XE 9 42
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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