Click here to Skip to main content
14,335,524 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello There,

I want to print a Treeview control with all nodes expanded.
The crystal report not supporting such type of printing.
How can i do that?

Thank in advance.
Posted
Comments
BillWoodruff 20-Dec-14 1:16am
   
CodeProject is your friend:

http://www.codeproject.com/Articles/6645/Printing-the-NET-TreeView-Control
Maciej Los 20-Dec-14 12:04pm
   
Sounds like answer ;)
Ramza360 1-Jan-15 13:40pm
   
That page does have a nice easy to use tool, but if you just need something quick and easy, my solution works nicely.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Have you tried doing a full expand on the tree?

After this use the inherited DrawToBitmap method.
You will have to perhaps behind the scenes, resize the control to show all items.

treeview1.ExpandAll();

// If the treeview is not large enough to show the items,
// you will have to resize it first to show all items.

// I think that's about max for one page.
// However you can most likely do some scaling.
treeview1.Size = new Size(600,850);

// Create a bitmap.
Bitmap bmp = new Bitmap(treeview1.Width, treeview1.Height);

// Draw the treeview to the bitmap.
treeview1.DrawToBitmap(bmp, treeview1.ClientRectangle);

// Add the image to the clipboard.
// Clipboard.SetDataObject(bmp) works just the same.
Clipboard.SetImage(bmp);

// Create the Word App
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();

// Hide the word application or true if you want to see this all happening.
wordApp.Visible = false;

// Set the Missing type object.
object missing = System.Type.Missing;
 
//Open the doc file
Microsoft.Office.Interop.Word.Document wordDoc = wordApp.Documents.Add(missing, missing, missing, missing);

// Get the range, beginning at doc is 0,0
Microsoft.Office.Interop.Word.Range rng = wordDoc.Range(0,0); 

// Paste the image to the doc.
rng.Paste(); 

// Print out the doc with default printer, no special settings.
wordDoc.PrintOut(missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);


Tested and works great..
   
v2
Comments
Raghubir_Sarkar 2-Jan-15 0:08am
   
Thank you Ramza. But my tree is too large having both Horizontal and vertical scrolls and about 250 to 300 nodes. how can i draw an image for this, it will shrink all the nodes.
Ramza360 2-Jan-15 9:54am
   
Ahhhh if it is this you must achieve, then following the link posted by BillWoodruff has the functionality your require. The tree view control needs to show all nodes that you want to print, but before printing, you would need to determine how the pages should be printed. The tool look as though it does all of this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100