Results 1 to 14 of 14

Thread: [RESOLVED] Print Preview of LISTVIEW Does NOT match printed Doc

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2012
    Posts
    540

    Resolved [RESOLVED] Print Preview of LISTVIEW Does NOT match printed Doc

    I have a document I am trying to print and in Print Preview and in tghe Printed Doc the 1st colum gets cut off some how.
    I have included screen shots.

    Print PreviewAttachment 95391


    I have set the columns in Listview to Autosize to the cell content but still it cuts off. not sure where to go. Here is my autosize code.
    Code:
    Private Sub btnSortLists_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSortLists.Click
    
    
            'PriceMatchStore.Shopping_List.View = View.Details
            'PriceMatchStore.Shopping_List.Columns.AddRange(New ColumnHeader() _
             '                          {New ColumnHeader With {.Name = "Item", .Text = "Item"}, _
              '                          New ColumnHeader With {.Name = "Brand", .Text = "Brand"}, _
               '                         New ColumnHeader With {.Name = "Size", .Text = "Size"}, _
                '                        New ColumnHeader With {.Name = "Coupon", .Text = "Coupon"}, _
                 '                       New ColumnHeader With {.Name = "PriceMatch", .Text = "PriceMatch"}})
    
    
            PriceMatchStore.StoreList.View = View.Details
            PriceMatchStore.StoreList.Columns.AddRange(New ColumnHeader() _
                                       {New ColumnHeader With {.Name = "Item", .Text = "Item"}, _
                                        New ColumnHeader With {.Name = "Brand", .Text = "Brand"}, _
                                        New ColumnHeader With {.Name = "Size", .Text = "Size"}, _
                                        New ColumnHeader With {.Name = "Price", .Text = "Price"}, _
                                        New ColumnHeader With {.Name = "Coupon", .Text = "Coupon"}})
    
            For Each m_row As System.Windows.Forms.DataGridViewRow In Me.ShoppingListView.Rows
                If m_row.Cells("clmcmbStore").Value IsNot Nothing Then
                    Dim store As String = m_row.Cells("clmcmbStore").Value.ToString
                    Dim group As New ListViewGroup(store, store)
                    If Not PriceMatchStore.StoreList.Groups.Cast(Of ListViewGroup).Any(Function(lvg) lvg.Name = store) Then
                        PriceMatchStore.StoreList.Groups.Add(group)
                    End If
    
                    Dim item As String = m_row.Cells("clmItem").Value.ToString
                    Dim brand As String = m_row.Cells("clmBrand").Value.ToString
                    Dim size As String = m_row.Cells("clmQTY").Value.ToString
                    Dim price As String = m_row.Cells("clmPrice").Value.ToString
                    Dim coupon As String = m_row.Cells("clmCoupon").Value.ToString
    
                    Dim lvItem As New ListViewItem(New String() {item, brand, size, price, coupon})
                    PriceMatchStore.StoreList.Items.Add(lvItem)
                    PriceMatchStore.StoreList.Groups.Cast(Of ListViewGroup).First(Function(lvg) lvg.Name = store).Items.Add(lvItem)
                    PriceMatchStore.StoreList.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent)
                    PriceMatchStore.StoreList.AutoResizeColumn(4, ColumnHeaderAutoResizeStyle.HeaderSize)
    
                End If
    
                'If m_row.Cells("clmItem").Value IsNot Nothing Then
    
                    'Dim item As String = m_row.Cells("clmItem").Value.ToString
                    'Dim brand As String = m_row.Cells("clmBrand").Value.ToString
                    'Dim size As String = m_row.Cells("clmQTY").Value.ToString
                    'Dim coupon As String = m_row.Cells("clmCoupon").Value.ToString
                    'Dim pricematch As String = m_row.Cells("clmPriceMatch").Value.ToString
    
                    'Dim lvItem As New ListViewItem(New String() {item, brand, size, coupon, pricematch})
                    'PriceMatchStore.Shopping_List.Items.Add(lvItem)
                   ' PriceMatchStore.Shopping_List.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent)
                    'PriceMatchStore.Shopping_List.AutoResizeColumn(3, ColumnHeaderAutoResizeStyle.HeaderSize)
                   ' PriceMatchStore.Shopping_List.AutoResizeColumn(4, ColumnHeaderAutoResizeStyle.HeaderSize)
    
                'End If
    
            Next
            PriceMatchStore.ShowDialog()
    
    
        End Sub
    I am only trying to print the storelist at this point
    Last edited by compgeek1979; Jan 19th, 2013 at 12:24 AM.

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Print Preview of LISTVIEW Does NOT match printed Doc

    Awkward customer that first column in a ListView in general for some reason. String measurement is off a touch and that gets multiplied in the print routine. So in the listViewPrinter code, make the following change.

    vb.net Code:
    1. Private Sub pd_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pd.PrintPage
    2.         Dim sf As New StringFormat(Drawing.StringFormat.GenericTypographic)
    3. ' comment out the following
    4.         'sf.Alignment = StringAlignment.Near  
    5.         'sf.LineAlignment = StringAlignment.Center
    6.  
    7.         'sf.Alignment = StringAlignment.Near
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2012
    Posts
    540

    Re: Print Preview of LISTVIEW Does NOT match printed Doc

    That is awesome. That fixed it. But i have one more nitpick that maybe you can help me with . The text seems like it is squeezed to the left of the cell. I know it is left justified, i would just like to see a hair more room on the left side of the words before the cell I have attached another screen shot.
    Attachment 95429

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Print Preview of LISTVIEW Does NOT match printed Doc

    I kinda knew you were gonna say that! I did notice that but didn't have time to explore it any further. I'll take another look at it when the world stops spinning for a minute or two.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2012
    Posts
    540

    Re: Print Preview of LISTVIEW Does NOT match printed Doc

    I appreciate that. Thank you so much

  6. #6
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Print Preview of LISTVIEW Does NOT match printed Doc

    Ok. I've made some adjustments to various parts of the class which should resolve all the problems (but probably won't now!) so here's the amended class in full. You'll probably need to adjust the print position a bit to the left (the example position of 50, 50 skews to the right with the amended class).
    Attached Files Attached Files
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2012
    Posts
    540

    Re: Print Preview of LISTVIEW Does NOT match printed Doc

    I am sorry i cant find where the Print position is.

    I mean I have this line of code
    Code:
            Dim printer As New listViewPrinter(StoreList, New Point(20, 10), chkBorder.Checked, StoreList.Groups.Count > 0)
            printer.print()
    but this adjust theposition of the entire printout. and no matter where i put it this is what i get
    Attachment 95457

    As you can see the inner borders are pushed to the right but also the last column is bigger than the width of the column. Im not sure how that changed.

  8. #8
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Print Preview of LISTVIEW Does NOT match printed Doc

    Drat. Sorry, I did my test with no grid lines. Back to the drawing board then!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  9. #9
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Print Preview of LISTVIEW Does NOT match printed Doc

    Ok. Think we've cracked it this time.
    Attached Files Attached Files
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2012
    Posts
    540

    Re: Print Preview of LISTVIEW Does NOT match printed Doc

    That Did it thanks.......

    ONe more question regarding Printing. How can I add a title at the top of Each list view and Make the title maybe centered witha bigger Font. BEcause When I print it prints both list views and a challanged person may not knwo what list is what......

  11. #11
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Print Preview of LISTVIEW Does NOT match printed Doc

    Further extension to the Class to include a title, called thus ...

    vb.net Code:
    1. Dim lp As New listViewPrinter(lview, New Point(50, 50), True, True, "Big Bold Title")

    If title is "", listview prints as before.
    Attached Files Attached Files
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2012
    Posts
    540

    Re: Print Preview of LISTVIEW Does NOT match printed Doc

    So would that go in here?
    Code:
    Public Class PriceMatchStore
    
    
        Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
            Me.DialogResult = System.Windows.Forms.DialogResult.OK
            Dim lp As New listViewPrinter(StoreList, New Point(50, 50), True, True, "Big Bold Title")
            Dim printer As New listViewPrinter(StoreList, New Point(20, 10), chkBorder.Checked, StoreList.Groups.Count > 0)
            printer.print()
            Dim printer2 As New listViewPrinter(Shopping_List, New Point(20, 10), chkBorder.Checked, Shopping_List.Groups.Count > 0)
            printer2.print()
            Me.Close()
        End Sub

  13. #13
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Print Preview of LISTVIEW Does NOT match printed Doc

    Quote Originally Posted by compgeek1979 View Post
    So would that go in here?
    Code:
    Public Class PriceMatchStore
    
    
        Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
            Me.DialogResult = System.Windows.Forms.DialogResult.OK
    
            Dim printer As New listViewPrinter(StoreList, New Point(20, 10), chkBorder.Checked, StoreList.Groups.Count > 0,"Title1")
            printer.print()
            Dim printer2 As New listViewPrinter(Shopping_List, New Point(20, 10), chkBorder.Checked, Shopping_List.Groups.Count > 0,"Title2")
            printer2.print()
            Me.Close()
        End Sub
    Just like that!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2012
    Posts
    540

    Re: Print Preview of LISTVIEW Does NOT match printed Doc

    I tried that but when i did i did not have the new ListViewPrinter code in...LOL. My mistake. Hey Thanks again so much for all your help. I have one more major issue to resolve before i can call it done. It is with sorting which i have another thread opened. Feel free to take a look if you think you can assist.

    http://www.vbforums.com/showthread.p...ox-But-Exclude

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