Results 1 to 2 of 2

Thread: Can't add tabpages from a seperate class

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Location
    London, England
    Posts
    142

    Can't add tabpages from a seperate class

    Good evening folks, I'm building a program that is threaded. While I can get the thread to work no problem, I can not seem to add pages to my tabcontrol from the class I'm using. Any idea's on what I'm doing wrong?

    frmMain is loaded first. Then the idea is to load the other tabpages using a separate thread as they take awhile.

    Code:
     Dim myformCal As New FrmCalender 'Load a new frmCalendar
                myformCal.TopLevel = False 'Make sure form is not top level
                myformCal.Dock = DockStyle.Fill 'Make sure to fit main form
                frmmain.tpCalendar.Controls.Add(myformCal)
                myformCal.Show() 'Show Form
    Any help would be appreciated.

    Redmo
    The universal aptitude for ineptitude makes any human accomplishment an incredible miracle -Col. John P. Stapp


    Please rate the posts that have helped. Makes us feel all warm and fuzzy

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Can't add tabpages from a seperate class

    Arae you saying that that code is running on a thread other than the main thread? If so then that's bad because you really should not be creating forms on different threads without a good reason.

    Apart from that, you can't access frmMain from a thread other than the UI thread. Either you're using the default instance there and you're actually adding tabs to a form you can't see or you're performing an illegal cross-thread operation. My guess is it's the first one. In that case I suggest that you follow the Blog link in my signature and read the post on default instances. It's OK to load data requiredby a form in a bakcground thread but anything that actually affects the form itself MUST be done in the UI thread. To see how, follow the CodeBank link in my signature and check out my post on access controls from worker threads.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width