I have recently written a client/server that houses a massive amount of data.
The client side makes extensive use of the Heirarchical Flex Grid control.
And naturaly I needed a method to print selected data from the grid.
And naturaly the printout needed to be in a grid form.

And naturaly I couldn't find any code to swipe in this area.

So here's the code in case anyone else finds themselves in the same situation.
Just be kind enough to give me a little credit for it.
Or if you are of exceptionaly noble character, send me money.

Here are some of the problems I faced.

1.) Printing a grid around the selected text.
2.) Printing (and displaying) all the text in a cell.
3.) The user not having a clue to the size of paper that he or she needs.
4.) The height and width of the selected rows and columns 
    being larger than all sizes of paper known to man.
5.) The Heirarchical Flex Grid "BUG".
    (Special thanks to the folks at FreeVBCode for helping me out with 
     this one.)

I have left notes all throughout the code as to how I addressed these issues.
But in short, I did this:

1.) Cussed........a lot
2.) Expanded the columns to display all the text in the cell by:
    First, setting the font to Courier. Courier is a fixed size font.
           Each character has the same twips, pixels, whatever.
           Courier is your friend, remember that.
    Second, setting the width of the column to the length of text.
           The longest length of text in the column, that is.
           So loop through the column to find it.
           I also had to multiply the the length by the Courier character-
           width, but you'll see all that in the code.
3.) Used the line method of the printer to create a grid on the print-out.
          Basicaly it's a really cool loop.(to me anyway) 
          Viewing the code explains it best.
4.) Gave the user a set number of print options as far a paper selections. 
          BUT, tested their option against the total selected column-widths, 
          and had the program automatically make a next-size-up selection for them.
          (with a message box for asking for their approval as a courtesy.)
5.) Using the total width of selected columns to determine lateral pages.
          You see, the printer will just dump, without any warning or apology of
          any sort, any columns that are out of bounds.
6.) Viewed as much code as I could on the subject.  I strongly recomend making a habit
          of viewing projects from other programers. There are a lot of fresh ideas
          out there, and you may save yourself from re-inventing the wheel.

     This code is trimmed down and just covers the basics of  getting a nice looking grid, 
on screen and on paper. There is a bit of an overhead cost, because of all the loops. But 
it really isn't noticable unless you are printing a massive amount of records, and even then 
its not to bad.
     I Can't guarantee that this project will work on every printer. I have the luxury of
having some pretty stud HP Laser jets on our network, and everything worked just peachy keen.

                    About my code: (With apologies to my logic instructer)
     I was a bit rushed in writing this, so please forgive any sloppiness. You will
also notice an extensive use of "GoSubs" in my procedures. A lot of "Better-Than-You"
programers take a long look down their noses at this, and as well they should,.....but,
if you use 'em right they can make debugging a lot easier. I use a kind-of pyramid
structure with a block of "goSubs" at the top, this helps cut down on wadeing through
code, and gives you an idea of what the procedure is all about.
Ex.,
Private Sub subThingy()
   Dim This, That, AndTheOtherThing as whatever
   GoSub SetThisStuffUp
   GoSub SetThatOtherStuffUp
   GoSub ProcessTheFirstStuff
   GoSub ProcessTheOtherStuff
   GoSub ResetAnyStuffThatNeedsResetting
   Exit Sub
SetThisStuffUp:
   a block of code that sets this stuff up
   Return
SetThatOtherStuffUp:
   a block of code that sets that other stuff up
   Return
ProcessTheFirstStuff:
   If Not(ScrewedUp(StuffYouSetUp)) Then
      a block of code that processes the first stuff
   Else
      GoSub ErrorExcuse 
   End if
   Return
ProcessTheOtherStuff:
   If Not(ScrewedUp(StuffYouSetUp)) Then
      a block of code that processes that other stuff
   Else
      GoSub ErrorExcuse 
   End if
   Return
ResetAnyStuffThatNeedsResetting:
   If Not(Royaly(ScrewedUp(StuffYouSetUp))) Then
      unset the stuff you set
   Else
      GoSub ErrorExcuse 
   End
   Return
ErrorExcuse:
   Explaination  = ScapeGoat(Find)
   Exit Building
End Sub

     Ok, the example is a bit redundant, but when you have long blocks of code,
 I have found that this structure is helpfull. I sincerely hope that this method 
helps you with the Flex grid. If you think you can improve on what I have done 
with the grid, or have a better method, for cryin'-out-loud, let me know. 
I haven't got much hair left to pull out.

     I would like to thank the guys at FreeVbCode again for their help. And a
salute to Nick Dawkes who, in my opinion is one helluva programer.  I have included
a mdb file with a couple of tables that I yanked out of the Northwind sample mdb.
So I guess I should thank Microsoft too.

Sincerely
Joe Kelly McPhail
