Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8719697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:51:39+00:00 2026-06-13T06:51:39+00:00

I have a TreeView control that I need to populate with a large 3

  • 0

I have a TreeView control that I need to populate with a large 3 tiered list of objects which is taking an incredible amount of time to build up. I’m doing the loading of the data on the background thread then sending the GUI updates over to the GUI thread, but there are just too many updates, for every time I add a node I have to send that across, then I have to call the ExpandSubTree() method to then expand all the sub nodes, which then fires off more expand events, and it crashes.

Is there a way I can build up the control and it’s open/closed state somehow on a background thread and then only marshall it over once it’s complete?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:51:40+00:00Added an answer on June 13, 2026 at 6:51 am

    Each tree view item had a property Children, if you bind each Tree View Item’s Children to an ObservableCollection you may add item to it from a BackGroundWorker or another thread. If you use the follow collection to bind the tree view item children you may add-remove children from background to the view. It use a synchronization context to add items to the view:

    public class ThreadSafeObservableCollection<T> : ObservableCollection<T>
    {
        private SynchronizationContext SynchronizationContext;
    
        public ThreadSafeObservableCollection()
        {
            SynchronizationContext = SynchronizationContext.Current;
    
            // current synchronization context will be null if we're not in UI Thread
            if (SynchronizationContext == null)
                throw new InvalidOperationException("This collection must be instantiated from UI Thread, if not, you have to pass SynchronizationContext to con                                structor.");
        }
    
        public ThreadSafeObservableCollection(SynchronizationContext synchronizationContext)
        {
            if (synchronizationContext == null)
                throw new ArgumentNullException("synchronizationContext");
    
            this.SynchronizationContext = synchronizationContext;
        }
    
        protected override void ClearItems()
        {
            this.SynchronizationContext.Send(new SendOrPostCallback((param) => base.ClearItems()), null);
        }
    
        protected override void InsertItem(int index, T item)
        {
            this.SynchronizationContext.Send(new SendOrPostCallback((param) => base.InsertItem(index, item)), null);
        }
    
        protected override void RemoveItem(int index)
        {
            this.SynchronizationContext.Send(new SendOrPostCallback((param) => base.RemoveItem(index)), null);
        }
    
        protected override void SetItem(int index, T item)
        {
            this.SynchronizationContext.Send(new SendOrPostCallback((param) => base.SetItem(index, item)), null);
        }
    
        protected override void MoveItem(int oldIndex, int newIndex)
        {
            this.SynchronizationContext.Send(new SendOrPostCallback((param) => base.MoveItem(oldIndex, newIndex)), null);
        }
    }
    

    Also i think that this articles must be useful to you:

    Simplifying the WPF TreeView by Using the ViewModel Pattern

    Custom TreeView Layout in WPF

    Hope this would be useful for you…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a asp.net treeview control that I need to be able to set
I have a treeview control that functions like a folder browser. Because loading the
I have a winforms TreeView control that allows you to browse an object hierarchy.
Hi The problem am having is that I have multiple TreeView control and each
In WPF, I have a custom control that inherits from TreeView. The code is
I have a TreeView that is bound to a XmlDataSource control. I've added some
I have a TreeView control in a Windows Forms application that is displaying my
I have a project that I'm working on that has a TreeView Control in
I have a TreeView control which displays two things: 1) Folder 2) Item Where
I have a control that inherits from TreeView (System.Windows.Controls.TreeView from WPF Framework) and it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.