rulec444

rulec444

  • NA
  • 81
  • 0

WindowForms with a UserControl

Feb 9 2005 12:31 PM
I may be trying to use a UserControl incorrectly - so I thought I would seek help. I have a main windows form with several tab pages. Each tabpage is the same format so I wanted to use a UserControl on each page. But, my problem comes in when I want to fill listboxes in the UserControl based upon which tabpage the user is on in the mainform. Example, In my main form - I have a variable, tabPageName and the value of this is set in the: tabPage_SelectedIndexChanged event. I've set a public property to hold this value, TabPageName. My issue is retrieving the tabPageName value within the user control. If I instantiate the main form when the UserControl is instantiated: MainForm form = new MainForm();//at the top of the page I receive an overflow error exception. If I try to instantiate the main form in the method that I'm using to fill the listboxes and use: Then try to use this to fill the listboxes: if(form.TabPageName == "first") //etc,,,, then the value of form.TabPageName is always null, it doesn't hold the previous value. Any ideas on how I can carry over these variables - if possible? Thanks for your help.

Answers (4)