I’m working on my own little product and I’m getting close to being done. Right now I need to make a UI for it. The UI uses a tree view and a fair number of list boxes. The problem that has been driving me nuts is that each time you update something my list boxes and tree view don’t really reflect the change. You have to switch to something else and come back in order to get it to reload. I hate that.
Calling all the Update, Redraw, and other methods on the controls is useless. They only trigger a WM_PAINT event and the control doesn’t think it needs to repaint so it doesn’t.
For instance: say you have a form with a tree control. In the tree control is a hierarchy that is three deep. The user can click on any of the nodes and change the label. Right now, in order for the user to see the update I have to sync back to the document (no biggie), and then reload the entire tree. Reloading the tree causes everything to close up. So if you have a few branches open, they won’t be anymore.
I hate UIs. Why can’t everybody just work in raw XML like Don Box intended?
Anyway, I finally drug my lazy butt to the workstation to figure out how this is supposed to be done. It isn’t actually that hard. The whole trick is to make a new item with all the stuff from the old, update it and use it to replace the old one. Simple!
The code looks something like:
(you can grab the project here)
I suspect the same technique will work with a listbox. I have no idea if this is the ‘best way’ but it is definitely a way that works. For me I just want to get this done so I can share it.
If you happen to know a better way and want to share it – give me a trackback.