I have a Nhibernate Database which provide the Data as hierarchical List<>. I have a TreeView in my Windows Forms GUI and a Backgroundworker which populate the TreeView with all Root Nodes and their Children (nothing more because of Lazy loading exception from NHibernate but this is okay because I expect that the user will have many Nodes in the TreeView).
The process to add the Root nodes and their children to the TreeView works pretty well but when I click on a Node to expand it all children of the children should be loaded from the Database and added to the TreeView. The Nodes are requested successfully from the Database and are stored in the buffer list (when Click on the node to expand it).
After that I tried a few ideas like rebuild the TreeView and repopulate it completely but with this solution I got the Problem that all expanded Nodes are collapsed so I tried to store the node that is expanded and it worked. But I am not quite happy with this solution, I got the feeling it can be done easier, because I don't want to repopulate the TreeView every time the User is expanding a Node.
How can I reload the Children of a TreeNode from the Database and display it in the TreeView without repopulating the whole TreeView?