Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Please help. Printing datagridview issue...

Please help. Printing datagridview issue...

Scheduled Pinned Locked Moved C#
helpcssdatabasegraphicstutorial
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JollyMansArt
    wrote on last edited by
    #1

    I have learned a lot doing this project with datagrid views. But I have one issue though minor to me is a major issue to the client. I have been working on this for over 2 weeks and can not find any examples to give me the output I am looking for. Please Help any Ideas please: What I need to be able to do is essentially print my database grid column header names vertically at a 90.0F angle. Not horizontally as the default. I have learned how to do this to the grid itself so it prints correctly on the screen. Which is:

    private void dgvReport_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
    {

            if (e.RowIndex == -1 && e.ColumnIndex >= 4)
            {
                e.PaintBackground(e.ClipBounds, true);
                Rectangle rect = 
                    this.dgvReport.GetColumnDisplayRectangle(e.ColumnIndex, true);
                Size titleSize =
                    TextRenderer.MeasureText(e.Value.ToString(), e.CellStyle.Font);
                if (this.dgvReport.ColumnHeadersHeight < titleSize.Width)
                    this.dgvReport.ColumnHeadersHeight = titleSize.Width;
    
                e.Graphics.TranslateTransform(0, titleSize.Width);
                e.Graphics.RotateTransform(-90.0F);
    
                e.Graphics.DrawString(e.Value.ToString(), e.CellStyle.Font, //this.Font,
                    Brushes.Black, new PointF(rect.Y, rect.X));
    
                e.Graphics.RotateTransform(90.0F);
                e.Graphics.TranslateTransform(0, -titleSize.Width);
                e.Handled = true;
            } 
            
        }
    

    But When I send the grid to the printer the columns are all horizontal not vertical. What can I do to print the columns vertical. Any examples anywhere?

    J 1 Reply Last reply
    0
    • J JollyMansArt

      I have learned a lot doing this project with datagrid views. But I have one issue though minor to me is a major issue to the client. I have been working on this for over 2 weeks and can not find any examples to give me the output I am looking for. Please Help any Ideas please: What I need to be able to do is essentially print my database grid column header names vertically at a 90.0F angle. Not horizontally as the default. I have learned how to do this to the grid itself so it prints correctly on the screen. Which is:

      private void dgvReport_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
      {

              if (e.RowIndex == -1 && e.ColumnIndex >= 4)
              {
                  e.PaintBackground(e.ClipBounds, true);
                  Rectangle rect = 
                      this.dgvReport.GetColumnDisplayRectangle(e.ColumnIndex, true);
                  Size titleSize =
                      TextRenderer.MeasureText(e.Value.ToString(), e.CellStyle.Font);
                  if (this.dgvReport.ColumnHeadersHeight < titleSize.Width)
                      this.dgvReport.ColumnHeadersHeight = titleSize.Width;
      
                  e.Graphics.TranslateTransform(0, titleSize.Width);
                  e.Graphics.RotateTransform(-90.0F);
      
                  e.Graphics.DrawString(e.Value.ToString(), e.CellStyle.Font, //this.Font,
                      Brushes.Black, new PointF(rect.Y, rect.X));
      
                  e.Graphics.RotateTransform(90.0F);
                  e.Graphics.TranslateTransform(0, -titleSize.Width);
                  e.Handled = true;
              } 
              
          }
      

      But When I send the grid to the printer the columns are all horizontal not vertical. What can I do to print the columns vertical. Any examples anywhere?

      J Offline
      J Offline
      JollyMansArt
      wrote on last edited by
      #2

      Found the solution

      StringFormat CellFormat = new StringFormat();
      //CellFormat.Trimming = StringTrimming.Word;
      CellFormat.FormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoClip | StringFormatFlags.NoWrap | StringFormatFlags.DirectionVertical;
      CellFormat.Alignment = StringAlignment.Center;

      g.DrawString(column.HeaderText,
      cell.Font(scale),
      new SolidBrush(cell.ForeColor()),
      CellBounds,
      CellFormat);

      The StringFormatFlags.DirectionVertical transforms the text vertically. Their is no need to picture draw the text vertically.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups