Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Treeview Thread

Treeview Thread

Scheduled Pinned Locked Moved C#
data-structureshelp
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    StephenMcAllister
    wrote on last edited by
    #1

    Hi, I am wanting to create a Treeview Thread for loading the tree. I tried just calling the procedure that loads it and I got a control invoke issue. I have never created a thread before so I am looking for a sample if possible. Thanks Stephen

    M L S 3 Replies Last reply
    0
    • S StephenMcAllister

      Hi, I am wanting to create a Treeview Thread for loading the tree. I tried just calling the procedure that loads it and I got a control invoke issue. I have never created a thread before so I am looking for a sample if possible. Thanks Stephen

      M Offline
      M Offline
      Marc Clifton
      wrote on last edited by
      #2

      StephenMcAllister wrote: I tried just calling the procedure that loads it and I got a control invoke issue. Controls should be manipulated in the application thread. At best, you can load your data into an in-memory table or some sort of structure using a thread, then populate the tree in the application thread. Marc MyXaml Advanced Unit Testing YAPO

      1 Reply Last reply
      0
      • S StephenMcAllister

        Hi, I am wanting to create a Treeview Thread for loading the tree. I tried just calling the procedure that loads it and I got a control invoke issue. I have never created a thread before so I am looking for a sample if possible. Thanks Stephen

        L Offline
        L Offline
        Luis Alonso Ramos
        wrote on last edited by
        #3

        There's somenthing you can do. I've not done it, but I'm thinking it might be possible. You can see this article[^] but the main steps are something like this:

        // 1. declare a delegate
        public delegate void AddTreeNodeHandler(TreeNode node);
        ...
        // 2. handler for the delegate
        void myAddTreeNode(TreeNode node)
        {
            treeView.Nodes.Add(node);
        }
        ...
        // 3. Start the thread (something like this.)
        // Pass any control created by main thread and delegate that will add node.
        MyThread t = new MyThread(treeView, new AddTreeNodeHandler(myAddTreeNode));
        Thread t = new Thread(new ThreadStart(t.ThreadMain));
        t.Start();
        ...
        // 4. Thread class
        class MyThread
        {
            Control ctl;
            AddTreeNodeHandler atn;
            void MyThread(Control ctl, AddTreeNodeHandler atn)
            {
                this.ctl = ctl;  // Save for later user
                this.atn = atn;
            } 
            void ThreadMain()
            {
                while(all nodes you need to add)
                {
                    TreeNode node = new TreeNode("text");
        
                    // This will post a call the delegate on the main thread,
                    // and not block until it returns. The second parameter is an
                    // array that will be passed as the arguments for the delegate.
                    ctl.BeginInvoke(atn, new object[] { node });
                }
            }
        }
        

        I did it all from the top of my head, without checking docs, and obviously without compiling it, so it might have some mistakes. But it's a good start for what your trying to do. -- LuisR


        Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!

        1 Reply Last reply
        0
        • S StephenMcAllister

          Hi, I am wanting to create a Treeview Thread for loading the tree. I tried just calling the procedure that loads it and I got a control invoke issue. I have never created a thread before so I am looking for a sample if possible. Thanks Stephen

          S Offline
          S Offline
          S Senthil Kumar
          wrote on last edited by
          #4

          This[^] article might help you. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups