I'm currently in a situation where a component created by a TreeViewItem requires a link to it's item. There's a couple of reasons for this:
-The component has a button that folds/unfolds the item's children. Therefore it needs to get / modify the open state of the item.
-The component's paint is affected by the item's state. The item's state can also be changed by other parts of the system that are unrelated to the component. A repaint should pick up the item's changed state.
-The component needs to select the item when it receives a mouseDown.
-The component can delete itself (delete a matching file in this case). It then needs to access the treeview to refresh it. It gets the treeview from the item.
-The component needs to access constant application specific data stored in the item.
I realize that the last two issues can be resolved by not passing along the item but the required data itself. For example i can pass the component it's tree view, and a struct containing the data needed. However this still leaves the first three issues, maybe issue one and three can be implemented by making a call to something other than the item, like the tree view itself?
I need some directions as to what the preferred approach is to handle dynamic data in the item that affects the component.
My current solution is to have the item and component reference eachother. These references are cleared in their destructors. So the item destructor clears the component->item reference and the component destructor clears the item->component reference. Then both the item and the component need to check if their reference is still valid before using it.