Results 1 to 4 of 4

Thread: [2005] Printing a treeview with extra info from datagridview

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    7

    [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.

    Any suggestions/examples

    would be greatly appreciated.

    Thanks
    Stoo

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Private Sub DisplayNodesText(ByVal nodes As TreeNodeCollection)
    2.     For Each node As TreeNode In nodes
    3.         MessageBox.Show(node.Text)
    4.  
    5.         'Call the method recursively.
    6.         Me.DisplayNodesText(node.Nodes)
    7.     Next node
    8. 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    7

    Re: [2005] Printing a treeview with extra info from datagridview

    I have attached an example of the effect i'm looking for.

    Any ideas?

    Thanks
    Stuart
    Attached Images Attached Images  

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width