How to speedup TreeNode text&color change in Winforms TreeView control, when 380k nodes are loaded and even Begin&EndUpdate ineffective?

  Kiến thức lập trình

I have a TreeView with 380k nodes. I use TreeView.BeginUpdate and TreeView.EndUpdate to populate it, but later I need to modify certain nodes text and color. I tried to do it without Begin&EndUpdate, I tried to do it with Begin&EndUpdate, but it still slow (around 15 seconds to refresh). That way is almost impossible to perform assigned task.

I read a lot of same questions about TreeView being slow, but it all ends in “use Begin&EndUpdate” or even “switch TreeView.Visible state”, but it all doesn’t help. What else can be done?

Now I thinking about caching drawn nodes images in a Dictionary<string, Image> text2img, but I don’t understand what I need to override to get that image. All I see is being able to change TreeView.DrawMode and subscribing to DrawNode event, but I don’t want to draw nodes by myself, I just want to cache them and feed cached image to the code that redraw them so slowly. Maybe, it’s wrong way, though.