Stonkie
Well-known member
- Joined
- Sep 12, 2007
- Messages
- 279
- Programming Experience
- 1-3
I am building a custom control containing a few control, including a TreeView (actually an extension of it). I need to know when the TreeView's nodes change without raising an event myself every time I change something.
I first thought it would not be possible, but then I concluded that since the TreeView knows when to redraw itself, there should be some way for the nodes to shout "yo man, you're outdated".
So, a few minutes later I'm in Reflector looking at the decompiled code of the TreeView, TreeNodeCollection and TreeNode looking for said YoManYoureOutdated() method. Instead, I found one called Realize in the TreeNode that seems to send a bunch of messages directly to the TreeView including WM_SETREDRAW!
So I came up with overriding the WndProc method of my TreeView to listen to WM_SETREDRAW (because it is the only message I know is sent consistently when a node changes), keeping a total count of the nodes (and sub nodes) in the TreeView and comparing if the nodes count changed before raising a NodesCountChanged event (because the TreeView can redraw even if its nodes didn't change).
This actually began as a question and I ended up solving the problem, but still I'm interested in anyone's solution because it can be pretty heavy to recursively count all nodes every time the TreeView repaints itself.
Hope this helps someone or maybe someone helps me!
I first thought it would not be possible, but then I concluded that since the TreeView knows when to redraw itself, there should be some way for the nodes to shout "yo man, you're outdated".
So, a few minutes later I'm in Reflector looking at the decompiled code of the TreeView, TreeNodeCollection and TreeNode looking for said YoManYoureOutdated() method. Instead, I found one called Realize in the TreeNode that seems to send a bunch of messages directly to the TreeView including WM_SETREDRAW!

So I came up with overriding the WndProc method of my TreeView to listen to WM_SETREDRAW (because it is the only message I know is sent consistently when a node changes), keeping a total count of the nodes (and sub nodes) in the TreeView and comparing if the nodes count changed before raising a NodesCountChanged event (because the TreeView can redraw even if its nodes didn't change).
This actually began as a question and I ended up solving the problem, but still I'm interested in anyone's solution because it can be pretty heavy to recursively count all nodes every time the TreeView repaints itself.
Hope this helps someone or maybe someone helps me!
