Results 1 to 18 of 18

Thread: printing a grid control

  1. #1

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    printing a grid control

    Hey all,

    I have a grid control that I populate right before I print it out... so my question is, how do I print the control with the gridlines and everything? Here's my code:

    VB Code:
    1. Printer.Print
    2.         Printer.Print "Manufacturer/Type/Size of Regulators"
    3.         optChoice(8).Value = True
    4.         GridCtrl.Row = 0
    5.         GridCtrl.Col = 0
    6.         For j = 0 To GridCtrl.Rows
    7.             For i = 0 To 4
    8.                 GridCtrl.Cols = i
    9.                 Printer.Print GridCtrl.Text;
    10.             Next i
    11.         Next j

    I know that's probably not even close, but I'm tryin here... when I do that, it empties the contents of of the control and I get a bunch of white space when it prints out... help?!
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    The code does exactly as you have instructed it to do... which is simply print the contents (the text) of each cell to the Printer.

    If you want to show gridlines... things get a little more complicated.

    Printer.Line (x1,y1) - (x2,y2),color

    is what you need to print lines to the Printer.

    You would have to develop a layout and then use
    Printer.CurrentX and Printer.CurrentY to properly position the text within the lines...

    But for my curiosity, why would you want the lines to print? A simple formated table with column and/or row labels will look nicer.

  3. #3

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    OK, well the gridlines weren't a huge concern, but may be with some of the other tables, but I'll figure that out later.

    The problem right now is that once it breaks into that second for loop, the gridctrl empties out and therefore has no more text to print. Any ideas why it might be doing this?
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    I have highlighted my suspect reason why... you were using the wrong property. .Col is a different property from .Cols



    VB Code:
    1. Printer.Print
    2.         Printer.Print "Manufacturer/Type/Size of Regulators"
    3.         optChoice(8).Value = True
    4.         GridCtrl.Row = 0
    5.         GridCtrl.Col = 0
    6.         For j = 0 To GridCtrl.Rows
    7.             For i = 0 To 4
    8.                 GridCtrl.[b]Col[/b] = i
    9.                 Printer.Print GridCtrl.Text;
    10.             Next i
    11.         GridCtrl.[b]Row[/b]=j
    12.         Next j

  5. #5

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    yay! new problem

    Now it's printing out jibberish... boxes, question marks, an accented 'a'..

    help... more!?
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  6. #6
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Well, you have to give more information, how big is this datagrid control (or is it a flexgrid control?), the entire subroutine you are using to print...

    You really need to check for discrepancies... In the code below,
    you use j=0 to gridctrl.rows but fail to implement for i = 0 to gridctrl.Cols (unless you are purposely limiting the output to the first 5 columns .. 0,1,2,3,4)


    VB Code:
    1. Printer.Print
    2.          [b]For j = 0 To GridCtrl.Rows
    3.             For i = 0 To 4[/b]
    4.                 GridCtrl.Col = i
    5.                 Printer.Print GridCtrl.Text;
    6.             Next i
    7.         GridCtrl.Row=j
    8.         Next j

  7. #7
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Also,

    Sometimes the printer driver gets messed up when fed improperly, and you have to turn off the printer for 8 seconds, reboot your computer, and turn the printer back on..

  8. #8

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    Sorry, I've changed the code since posting it the first time.

    The columns will always be the same regardless. The rows however will not. And this is a GridCtrl, not a FlexGrid.

    VB Code:
    1. Printer.Print
    2.         Printer.Print "Manufacturer/Type/Size of Regulators"
    3.         optChoice(8).Value = True
    4.         GridCtrl.Row = 0
    5.         GridCtrl.Col = 0
    6.         For j = 0 To GridCtrl.Rows - 1
    7.             For i = 0 To GridCtrl.Cols - 1
    8.                 GridCtrl.Col = i
    9.                 If i = GridCtrl.Cols - 1 Then
    10.                 Printer.Print GridCtrl.Text
    11.                 Else
    12.                 Printer.Print GridCtrl.Text;
    13.                 End If
    14.             Next i
    15.             GridCtrl.Row = j
    16.         Next j

    Also, am I right by putting a semi-colon after the statement that it will not move to the next line before printing? Or is that unnecessary?
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  9. #9

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    Originally posted by nemaroller
    Also,

    Sometimes the printer driver gets messed up when fed improperly, and you have to turn off the printer for 8 seconds, reboot your computer, and turn the printer back on..
    I'm printing to a network laser printer, but I guess the buffer could get screwed up, huh?
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  10. #10
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    You are correct about the semicolon thing....

    As far as what control you are using, this doesn't appear to be an intrinsic control of VB, (one that comes with VB) but rather a third-party control.... one which was bought or downloaded, in which case, you will have to search the documentation for it.

    I would highly suggest clearing the network printer by shutting it off... you could of course simply test that theory by trying to print a document from MS WORD, or EXCEL, or any other application....

  11. #11
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    GridCtrl appears to be a control for eMbedded VB for pocketpcs...

  12. #12

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    This is not a third party control... it came with VB 6.0 and I use it because that's what I have to use with my handheld projects and I understand it.

    Also, I know there's nothing wrong with the printer, because it prints out other statements just fine. It's just the contents of the GridCtrl that it screws up.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  13. #13

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    Originally posted by nemaroller
    GridCtrl appears to be a control for eMbedded VB for pocketpcs...
    exactly, but it's also a control for VB 6, as far as I can tell.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  14. #14
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Well, your code appears to be correct...

    IT was printing out the datagrid content's before you came here, but with whitespace right?

  15. #15

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    yes, but that's because I was basically wiping the contents of the grid before printing...

    Maybe I should consider using a different Grid...

    I've never used a MSFlexGrid, but I'm playing with it.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  16. #16
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    The flexgrid shares most of the same properties with the control you are using, in fact, the control you are using was based off it.

    You would probably not need to change a thing, other than change name property of the msflexgrid to gridcntrl1 or something...

  17. #17

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    Yeah, I did that. Now I need to figure out how to print out the flexgrid.

    :: goes to do search ::
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  18. #18
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Use the code u were using for the datagrid...

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