[2005] Printing a treeview with extra info from datagridview
I have an application with a dataview that is populated with a self join relationship. Suppliers and their sub distributors.
This can then be filtered with the accompanying treeview control.
I am looking at a way to print all nodes beneath a selected level with their nesting level displayed, along with extra fields from their full record in the datagridview.
Re: [2005] Printing a treeview with extra info from datagridview
1. A tree is a recursive structure so to traverse a tree you should use a recursive method, e.g.
vb Code:
Private Sub DisplayNodesText(ByVal nodes As TreeNodeCollection)
For Each node As TreeNode In nodes
MessageBox.Show(node.Text)
'Call the method recursively.
Me.DisplayNodesText(node.Nodes)
Next node
End Sub
You can start that ball rolling by passing the Nodes property of the TreeView itself or the Nodes property of one particular node if you want that to be the root of your search.
2. All .NET printing is done the same way. You create a PrintDocument object, call its Print method and handle its PrintPage event. In the PrintPage event handler you use the e.Graphics property to draw your printed output using standard GDI+.
3. When you build the tree you should assign the source DataRow to the Tag property each time you create a node. That way you can traverse the tree and get direct access to the source row for each node as you visit it.
Re: [2005] Printing a treeview with extra info from datagridview
Did I just imagine giving some ideas in my previous post? Have you tested my recursive method to see if it can visit every node? Have you tried my suggestion of assigning DataRows to the Tag properties of the nodes they relate to? Have you then tried my recursive method again to see if you can get all the DataRows? Have you read the documentation for the PrintDocument class and its Print and PrintPage members? Have you searched Google and MSDN for printing ".net"? You have plenty of avenues to investigate. If there's something about the suggestions you don't understand then say so and ask for clarification. Ignoring legitimate advice is a good way to not get further advice.
Also, don't try to run before you can walk. That is relatively advanced printing. Don't even try it until you understand how .NET printing works. If you can't print "Hello World" then you can't possibly print what you are asking for. If someone provided code you wouldn't understand it anyway because you don't understand the basics. As I said, research printing in .NET in general, get to understand the principles and then apply them to your specific situation.