Results 1 to 3 of 3

Thread: Datagridview print graphics

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Location
    Canada right now
    Posts
    15

    Datagridview print graphics

    I used to use VS2003 and the DataGrid control. Now I have been using the VS 2005 DataGridView control (I don't even see the old DataGrid in the toolbox).

    I accomplished printing a DataGrid as a Graphic (not text) with

    public DataGrid gridtoprint = new DataGrid();

    (blah, blah, other stuff to fill the grid)

    private void PrintDocument1_PrintPage( System.Object sender, System.Drawing.Printing.PrintPageEventArgs e )
    {
    PaintEventArgs myPaintArgs = new PaintEventArgs( e.Graphics, new Rectangle( new Point( 0, 0 ), this.Size ) );
    this.InvokePaint( gridtoprint, myPaintArgs );
    }

    But try this after simple substitution of:

    public DataGridView gridtoprint = new DataGridView();

    and some really weird things happen. Yes, the grid prints. But the elements are not in the cells. Instead, they are all packed into the top left corner of the grid in about 0.05 point type.

    Is there a simple solution that allows my continued use of the new DataGridView control or do I need to go back to DataGrids for this functionality??

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

    Re: Datagridview print graphics

    That's a very inadvisable way to print a grid. What if there are more rows than can fit on the visible grid? There will be no way to print them. You should check out this thread. It provides an excepllent means to print the contents of DataGrids and DataGridViews. The code is VB but the principles are exactly the same. If you don't want to convert the code then just compile it into a VB DLL and use it from your C# app.
    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
    Aug 2007
    Location
    Canada right now
    Posts
    15

    Re: Datagridview print graphics

    Thanks

    I agree, and I have a good, working procedure for printing a grid.

    However, I have an application where I want to print the grid as a graphic.

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