Solved

vb.net printing hasmorepages with internal loops.

Posted on 2008-06-16
9
1,015 Views
Last Modified: 2013-11-26
I need to figure out how to print checks for customers. I have two listviews, one with customer name and one with item number and price that is owed to the customer.  I have attached the code. I have an outer loop for the customer and an inner loop for the items. The items need to be totaled and the total printed on a check with the customer name.  Three checks per page (all different customers).
 
I have it working, but confused about hasmorepages. Worth 500 points.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
                
        PrintPreviewDialog1.Document = PrintDocument1
        Me.CheckNumber = 1
 
        Dim result As DialogResult = PrintPreviewDialog1.ShowDialog()
 
        ' If the result is OK then print the document.
        If (result = Windows.Forms.DialogResult.OK) Then
            'PrintDocument1.Print()
        End If
    End Sub
 
 
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
 
        ' Initialize the font to be used for printing.
        Dim font As New Font("Microsoft Sans Serif", 12)
        Dim intLVUbound As Integer
        Dim intLVUboundC As Integer
        Dim intLVIdx As Integer
        Dim intLVIdxC As Integer
        Dim ItemNo As String
        Dim ItemNo2 As String
        Dim x1, x2, x3, x4, x5, x6, x7, x8, x9 As Integer
        Dim y1, y2, y3, y4, y5, y6, y7, y8, y9 As Integer
        Dim X As Integer = 1
        Dim Y As Integer = 0
        Dim Col1 As String = ""
        Dim Col1x As String = ""
        Dim Col2 As String = ""
        Dim Col2Parsed As String = ""
        Dim decAmount As Decimal
        Dim decAmount2 As Decimal
        Dim strAmount As String = Nothing
        Dim CoName As String = "The Consignment Shop"
        Dim Address1 As String = "6906 Camp Bowie Blvd."
        Dim Address2 As String = "Suite 132"
        Dim CityStateZip As String = "Fort Worth, TX. 76116"
        Dim ForLine As String = "John Doe Consignment"
        Dim Now As DateTime = DateTime.Now
        Dim ShortDate As String = Now.ToString("d")
        Dim MAX_PAGE_COUNT As Integer = 2
        intLVUboundC = lvwConsignors.Items.Count - 1  'Get number of Consignors
 
        intLVUbound = lvwItems.Items.Count - 1  'Get number of Items for this consignor
 
        'Define the Company Header Position
        x1 = 35 : y1 = 30 ' Company Name
        x2 = 35 : y2 = 45 ' Address 1
        x3 = 35 : y3 = 60 ' Address 2
        x4 = 35 : y4 = 75 ' City/State/Zip
 
        x5 = 678 : y5 = 68 ' Date
        x6 = 110 : y6 = 120 'John Doe y is up and down, x is left and right
        x7 = 675 : y7 = 120 'Amount Box
        x8 = 42 : y8 = 150 'Money String.
        x9 = 90 : y9 = 185  'For Line
 
        'Start the Loop for each Consignor
        For intLVIdxC = 0 To intLVUboundC - 1
 
            'write the Consignors Info on the Check
            e.Graphics.DrawString(CoName, font, Brushes.Black, x1, y1)
            e.Graphics.DrawString(Address1, font, Brushes.Black, x2, y2)
            e.Graphics.DrawString(Address2, font, Brushes.Black, x3, y3)
            e.Graphics.DrawString(CityStateZip, font, Brushes.Black, x4, y4)
 
            'Get the detail for the check and add up the amounts
            For intLVIdx = 0 To intLVUbound - 1
 
                Col1 = lvwConsignors.Items(intLVIdxC).SubItems(1).Text 'Get the Item
                Col1x = lvwConsignors.Items(intLVIdxC).Tag 'Get the Consignor ID
                ItemNo = lvwItems.Items(intLVIdx).Tag 'Get the Item Number
                ItemNo2 = lvwItems.Items(intLVIdx).Tag 'Get the Item Number
                MarkAsPaid(ItemNo) 'Mark This Item As Paid
 
                Col2 = lvwItems.Items(intLVIdx).SubItems(3).Text
                Col2Parsed = Col2.Substring(1)
                'Process the text String for Dollar Amount
                'convert the text into a decimal
                decAmount = Convert.ToDecimal(Col2Parsed)
 
                'set the number of decimal places to 2
                decAmount = Decimal.Round(decAmount, 2)
                'Add the Amounts
                decAmount2 = decAmount2 + decAmount
                strAmount = DecimalToText.ConvertDecimalToText(decAmount2)
                Call AddToLog(ItemNo, Col2Parsed, ItemNo2, Col1x) 'Add This Item To the Transaction Log
 
            Next ' Next Item No.
 
            'For X = X To 3 'Start Check Counter - 3 Checks per page
            'Process the text String for Dollar Amount
            e.Graphics.DrawString(ShortDate, font, Brushes.Black, x5, y5)
            e.Graphics.DrawString(Col1, font, Brushes.Black, x6, y6)
            e.Graphics.DrawString(decAmount2, font, Brushes.Black, x7, y7)
            e.Graphics.DrawString(strAmount, font, Brushes.Black, x8, y8)
            e.Graphics.DrawString(ForLine, font, Brushes.Black, x9, y9)
            e.Graphics.DrawString("* * * * * * * * * * * * * * * * * * * * * * * *", font, Brushes.Black, x8 + 360, y8 + 4)
 
 
            'Next X
 
 
            'Change print position on page
            y1 = y1 + 350
            y2 = y2 + 350
            y3 = y3 + 350
            y4 = y4 + 350
            y5 = y5 + 350
            y6 = y6 + 350
            y7 = y7 + 350
            y8 = y8 + 350
            y9 = y9 + 350
 
            Call UpdateBalances(decAmount2, Col1x)
 
        Next ' Next Consignor
 
 
        If Me.CheckNumber = MAX_PAGE_COUNT Then
 
            'We have printed all the pages.
            e.HasMorePages = False
            'Reset the page number because if this is a preview and the user presses
            'the Print button the printing routine will be executed a second time.
            Me.CheckNumber = 1
        Else
            'There are more pages to print. 
            e.HasMorePages = True
            'Increment the page number.
            Me.CheckNumber += 1
        End If
 
    End Sub

Open in new window

0
Comment
Question by:wsenter
  • 5
  • 3
9 Comments
 
LVL 18

Expert Comment

by:jcoehoorn
ID: 21797609
HasMorePages tells the print document object whether or not to fire another PrintPage event.  If HasMorePages is true, than it will fire another PrintPage event so you can print the next page.  If it is false, it won't.
0
 
LVL 27

Expert Comment

by:planocz
ID: 21797650
Look on your other posting.
I fixed your problem.
0
 
LVL 1

Author Comment

by:wsenter
ID: 21797704
no planocz.  This one is way different if you look closely.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 27

Expert Comment

by:planocz
ID: 21802887
OK just to add to the fun!
I have code that you can uase in the Listview.
You should do all your work in the listview , Then print the checks like you have in the other posting.
'FORM 1
Public Class frmBalanceColum
    'counters for listview
    Private vCnt As Short = 0
    Private v As Short = 0
    Private sortColumn As Integer = -1
    Private arrID() As String
    Private iCounter As Short
    Private Sub frmBalanceColum_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        InitializeListView()
    End Sub
    Private Sub InitializeListView()
 
        With Listview1
            .Columns.Add("Edit", 50, HorizontalAlignment.Left)
            .Columns.Add("Descrption", 100, HorizontalAlignment.Left)
            .Columns.Add("Add", 70, HorizontalAlignment.Left)
            .Columns.Add("Subtract", 70, HorizontalAlignment.Left)
            .Columns.Add("Balance", 110, HorizontalAlignment.Left)
        End With
        ReDim arrID(10)
        'FOR TESTING ONLY
        'STRING ARRAY ---- ID & "," & Add & "!" & Subtract & "|" & Balance# & ";" & ID
        arrID(0) = "Car Balance" & "," & "100.00" & "!" & "50.00" & "|" & "0" & ";" & "1"
        arrID(1) = "House Bill" & "," & "250.00" & "!" & "1.00" & "|" & "0" & ";" & "2"
        arrID(2) = "Electric Bill" & "," & "450.00" & "!" & ".50" & "|" & "0" & ";" & "3"
        arrID(3) = "Water Bill" & "," & "500.00" & "!" & "1.01" & "|" & "0" & ";" & "4"
        For iCounter = 0 To 3
            LoadListView(arrID)
        Next
    End Sub
#Region " Checkbox Changes "
    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked = True Then
            Dim itm As ListViewItem
            Listview1.SelectedItems().Clear()
            For Each itm In Listview1.CheckedItems
                itm.Checked = False
            Next
            CheckBox1.Checked = False
            CheckBox2.Checked = False
        End If
    End Sub
    Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
        If CheckBox2.Checked = True Then
            Dim itm As ListViewItem
            For Each itm In Listview1.Items
                itm.Checked = True
            Next
        End If
    End Sub
    Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
        If CheckBox3.Checked = True Then
            Cursor.Current = Cursors.WaitCursor
            Dim itm As ListViewItem
            Listview1.SelectedItems().Clear()
            For Each itm In Listview1.CheckedItems
                itm.Remove()
            Next
            For Each itm In Listview1.SelectedItems
                itm.Remove()
            Next
            CheckBox3.CheckState = CheckState.Unchecked
            lblTotalcnt.Text = Listview1.Items.Count
            Listview1.Refresh()
            lblTotalcnt.Refresh()
        End If
    End Sub
#End Region
    Private Sub LoadListView(ByVal listArray() As String)
        Dim iID As Integer
 
        Try
            'INCOMING STRING ARRAY ---- ID & "," & Add & "!" & Subtract & "|" & Balance# & ";" & ID
            iID = Val(listArray(v).Substring(listArray(v).IndexOf(";") + 1))
            With Listview1
                .Items.Add(iID.ToString("00"))
                Select Case iID
                    Case 1
                        .Items(vCnt).BackColor = Color.WhiteSmoke
                        .Items(vCnt).ForeColor = Color.Green
                    Case 2 To 3
                        .Items(vCnt).BackColor = Color.WhiteSmoke
                        .Items(vCnt).ForeColor = Color.Blue
                    Case 4 To 9
                        .Items(vCnt).BackColor = Color.White
                        .Items(vCnt).ForeColor = Color.Magenta
                    Case Is >= 10
                        .Items(vCnt).BackColor = Color.White
                        .Items(vCnt).ForeColor = Color.Red
                End Select
                .Items(vCnt).SubItems.Add(listArray(v).Substring(0, listArray(v).IndexOf(",")))
                .Items(vCnt).SubItems.Add(listArray(v).Substring(listArray(v).IndexOf(",") + 1, listArray(v).IndexOf("!") - listArray(v).IndexOf(",") - 1))
                .Items(vCnt).SubItems.Add(listArray(v).Substring(listArray(v).IndexOf("!") + 1, listArray(v).IndexOf("|") - listArray(v).IndexOf("!") - 1))
                .Items(vCnt).SubItems.Add(listArray(v).Substring(listArray(v).IndexOf("|") + 1, listArray(v).IndexOf(";") - listArray(v).IndexOf("|") - 1))
                vCnt += 1
                v += 1
            End With
        Catch Exp As Exception
            MsgBox(Exp.Message, MsgBoxStyle.Critical, "Error Loading ListView Reports")
            Cursor.Current = Cursors.Default
        Finally
        End Try
    End Sub
 
    Private Sub Listview1_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles Listview1.ItemCheck
        Dim sTemp As String = sender.Items(e.Index).SubItems.Item(0).Text
        Dim d As Integer
 
        'Select only one item at a time
        If e.CurrentValue = CheckState.Unchecked Then
            If Listview1.CheckedIndices.Count > 0 Then
                Dim itm As ListViewItem
                Listview1.SelectedItems().Clear()
                For Each itm In Listview1.CheckedItems
                    itm.Checked = False
                Next
            End If
        End If
 
        'Show progress of the checked boxes
        If e.CurrentValue = CheckState.Unchecked Then
            Listview1.Columns.RemoveAt(0)
            Listview1.Columns.Insert(0, "Edit", 125, HorizontalAlignment.Left)
            sender.Items(e.Index).UseItemStyleForSubItems = False
            sender.Items(e.Index).SubItems.Item(0).Text = sTemp & " 'Editing' "
            sender.Items(e.Index).subitems.item(0).ForeColor = Color.Orange
            For d = 1 To 4
                With sender
                    Select Case CType(sTemp, Integer)
                        Case 1
                            .Items(e.Index).SubItems.Item(d).BackColor = Color.WhiteSmoke
                            .Items(e.Index).SubItems.Item(d).ForeColor = Color.Green
                        Case 2 To 3
                            .Items(e.Index).SubItems.Item(d).BackColor = Color.WhiteSmoke
                            .Items(e.Index).SubItems.Item(d).ForeColor = Color.Blue
                        Case 4 To 9
                            .Items(e.Index).SubItems.Item(d).BackColor = Color.WhiteSmoke
                            .Items(e.Index).SubItems.Item(d).ForeColor = Color.Magenta
                        Case Is >= 10
                            .Items(e.Index).SubItems.Item(d).BackColor = Color.White
                            .Items(e.Index).SubItems.Item(d).ForeColor = Color.Red
                    End Select
                End With
            Next
            txtAdd.Text = sender.Items(e.Index).SubItems.Item(2).Text
            txtSubtract.Text = sender.Items(e.Index).SubItems.Item(3).Text
        Else
            If Listview1.CheckedIndices.Count <= 1 Then
                Listview1.Columns.RemoveAt(0)
                Listview1.Columns.Insert(0, "Edit", 50, HorizontalAlignment.Left)
            End If
            With sender
                Select Case CType(sTemp.Substring(0, 3), Integer)
                    Case 1
                        .Items(e.Index).BackColor = Color.WhiteSmoke
                        .Items(e.Index).ForeColor = Color.Green
                    Case 2 To 3
                        .Items(e.Index).BackColor = Color.WhiteSmoke
                        .Items(e.Index).ForeColor = Color.Blue
                    Case 4 To 9
                        .Items(e.Index).BackColor = Color.WhiteSmoke
                        .Items(e.Index).ForeColor = Color.Magenta
                    Case Is >= 10
                        .Items(e.Index).BackColor = Color.White
                        .Items(e.Index).ForeColor = Color.Red
                End Select
            End With
            sender.Items(e.Index).SubItems.Item(0).Text = sTemp.Substring(0, sTemp.Length - 11)
            txtAdd.Text = "0"
            txtSubtract.Text = "0"
        End If
 
        With sender
            Select Case .Items(e.Index).SubItems.Item(4).text
                Case Is >= 100
                    .Items(e.Index).SubItems.Item(4).BackColor = Color.WhiteSmoke
                    .Items(e.Index).SubItems.Item(4).ForeColor = Color.Green
                Case Is >= 1
                    .Items(e.Index).SubItems.Item(4).BackColor = Color.WhiteSmoke
                    .Items(e.Index).SubItems.Item(4).ForeColor = Color.Blue
                Case 0
                    .Items(e.Index).SubItems.Item(4).BackColor = Color.WhiteSmoke
                    .Items(e.Index).SubItems.Item(4).ForeColor = Color.Magenta
                Case Is < 0
                    .Items(e.Index).SubItems.Item(4).BackColor = Color.White
                    .Items(e.Index).SubItems.Item(4).ForeColor = Color.Red
            End Select
        End With
    End Sub
    Private Sub Listview1_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles Listview1.ColumnClick
        ' Determine whether the column is the same as the last column clicked.
        If e.Column <> sortColumn Then
            ' Set the sort column to the new column.
            sortColumn = e.Column
            ' Set the sort order to ascending by default.
            Listview1.Sorting = SortOrder.Ascending
        Else
            ' Determine what the last sort order was and change it.
            If Listview1.Sorting = SortOrder.Ascending Then
                Listview1.Sorting = SortOrder.Descending
            Else
                Listview1.Sorting = SortOrder.Ascending
            End If
        End If
        ' Call the sort method to manually sort.
        Listview1.Sort()
        ' Set the ListViewItemSorter property to a new ListViewItemComparer object.
        Listview1.ListViewItemSorter = New ListViewItemComparer(e.Column, Listview1.Sorting)
    End Sub
 
    Private Sub btnSubtract_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubtract.Click
        Dim item As ListViewItem = Nothing
        Dim Balance_Sub As Double = 0.0
        Dim checkedItems As ListView.CheckedListViewItemCollection = Listview1.CheckedItems
        For Each item In checkedItems
            Balance_Sub = Double.Parse(item.SubItems(4).Text) - txtSubtract.Text
        Next
        item.SubItems(4).Text = Format(Balance_Sub, "###.00")
        Check_Balance(item)
    End Sub
 
    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim item As ListViewItem = Nothing
        Dim Balance_Add As Double = 0.0
        Dim checkedItems As ListView.CheckedListViewItemCollection = Listview1.CheckedItems
        For Each item In checkedItems
            Balance_Add = txtAdd.Text + Double.Parse(item.SubItems(4).Text)
        Next
        item.SubItems(4).Text = Format(Balance_Add, "###.00")
        Check_Balance(item)
    End Sub
    Private Sub Check_Balance(ByVal item As Object)
        Select Case CType(item.SubItems(4).Text, Integer)
            Case Is >= 100
                item.SubItems(4).BackColor = Color.WhiteSmoke
                item.SubItems(4).ForeColor = Color.Green
            Case Is >= 1
                item.SubItems(4).BackColor = Color.WhiteSmoke
                item.SubItems(4).ForeColor = Color.Blue
            Case 0
                item.SubItems(4).BackColor = Color.WhiteSmoke
                item.SubItems(4).ForeColor = Color.Magenta
            Case Is < 0
                item.SubItems(4).BackColor = Color.White
                item.SubItems(4).ForeColor = Color.Red
        End Select
    End Sub
 
End Class
 
'CLASS
' Implements the manual sorting of items by columns.
Class ListViewItemComparer
    Implements IComparer
    Private col As Integer
    Private order As SortOrder
 
    Public Sub New()
        col = 0
        order = SortOrder.Ascending
    End Sub
    Public Sub New(ByVal column As Integer, ByVal order As SortOrder)
        col = column
        Me.order = order
    End Sub
    Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer _
                        Implements System.Collections.IComparer.Compare
        Dim returnVal As Integer = -1
        returnVal = [String].Compare(CType(x, ListViewItem).SubItems(col).Text, _
                        CType(y, ListViewItem).SubItems(col).Text)
        ' Determine whether the sort order is descending.
        If order = SortOrder.Descending Then
            ' Invert the value returned by String.Compare.
            returnVal *= -1
        End If
        Return returnVal
    End Function
End Class

Open in new window

0
 
LVL 27

Accepted Solution

by:
planocz earned 500 total points
ID: 21807216
Ok, I made the above sample a little more to what I was talking about in using the Listview.
Place the code in a new project and run.
Then click on the select all checkbox.
Then click on the PreView Buttom.
'FORM 1
Imports System.Drawing
Imports System.Drawing.Printing
Public Class frmViewChecks
    'counters for listview
    Private vCnt As Short = 0
    Private v As Short = 0
    Private sortColumn As Integer = -1
    Private arrID() As String
    Private iCounter As Short
 
    Dim X As Integer = 0
    Dim Y As Integer = 0
    Dim topMargin As Integer = 35
    Dim count As Integer = 0
    Dim Col1 As String = ""
    Dim Col1x As String = ""
    Dim Col2 As String = ""
    Dim Col2Parsed As String = ""
    Dim Now As DateTime = DateTime.Now
    Dim ShortDate As String = Now.ToString("d")
    Dim x1, x2, x3, x4, x5, x6, x7, x8, x9, x10 As Integer
    Dim y1, y2, y3, y4, y5, y6, y7, y8, y9, y10 As Integer
    Dim decAmount As Decimal
    Dim decAmount2 As Decimal
    'define a string to hold the converted value
    Dim strAmount As String = Nothing
 
    Private WithEvents mDoc As New PrintDocument()
    Private mFont As New Font("Courier New", 12)
    Private Sub Form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        InitializeListView()
    End Sub
    Private Sub InitializeListView()
        With Listview1
            .Columns.Add("Company ID", 100, HorizontalAlignment.Left)
            .Columns.Add("Company Name", 150, HorizontalAlignment.Left)
            .Columns.Add("Current Balance", 150, HorizontalAlignment.Left)
            .Columns.Add("New Balance", 150, HorizontalAlignment.Left)
        End With
        ReDim arrID(10)
        'FOR TESTING ONLY
        'STRING ARRAY ---- ID & "," & Company Name & "!" & Current Balance & ";" & New Balance   
        arrID(0) = "ID1" & "," & "Company Name1" & "!" & "1,000.00" & ";" & "0"
        arrID(1) = "ID2" & "," & "Company Name2" & "!" & "548.00" & ";" & "0"
        arrID(2) = "ID3" & "," & "Company Name3" & "!" & "225.84" & ";" & "0"
        arrID(3) = "ID4" & "," & "Company Name4" & "!" & "23,168.40" & ";" & "0"
        arrID(4) = "ID5" & "," & "Company Name5" & "!" & "2,383.00" & ";" & "0"
        arrID(5) = "ID6" & "," & "Company Name6" & "!" & "315.00" & ";" & "0"
        arrID(6) = "ID7" & "," & "Company Name7" & "!" & "948.00" & ";" & "0"
        arrID(7) = "ID8" & "," & "Company Name8" & "!" & "266.00" & ";" & "0"
        arrID(8) = "ID9" & "," & "Company Name9" & "!" & "587.00" & ";" & "0"
        arrID(9) = "ID10" & "," & "Company Name10" & "!" & "4,884.00" & ";" & "0"
        For iCounter = 0 To 9
            LoadListView(arrID)
        Next
    End Sub
#Region " Checkbox Changes "
    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked = True Then
            Dim itm As ListViewItem
            Listview1.SelectedItems().Clear()
            For Each itm In Listview1.CheckedItems
                itm.Checked = False
            Next
            CheckBox1.Checked = False
            CheckBox2.Checked = False
        End If
    End Sub
    Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
        If CheckBox2.Checked = True Then
            Dim itm As ListViewItem
            For Each itm In Listview1.Items
                itm.Checked = True
            Next
        End If
    End Sub
    Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
        If CheckBox3.Checked = True Then
            Cursor.Current = Cursors.WaitCursor
            Dim itm As ListViewItem
            Listview1.SelectedItems().Clear()
            For Each itm In Listview1.CheckedItems
                itm.Remove()
            Next
            For Each itm In Listview1.SelectedItems
                itm.Remove()
            Next
            CheckBox3.CheckState = CheckState.Unchecked
            lblTotalcnt.Text = Listview1.Items.Count
            Listview1.Refresh()
            lblTotalcnt.Refresh()
        End If
    End Sub
#End Region
    Private Sub LoadListView(ByVal listArray() As String)
        Dim sID As String
        Dim sBalance As String
 
        Try
            'INCOMING STRING ARRAY ---- ID & "," & Company Name & "!" & Current Balance & ";" & New Balance      
            sID = listArray(v).Substring(0, listArray(v).IndexOf(",") - listArray(v).IndexOf("|") - 1)
            sBalance = listArray(v).Substring(listArray(v).IndexOf("!") + 1, listArray(v).IndexOf(";") - listArray(v).IndexOf("!") - 1)
            With Listview1
                .Items.Add(sID)
                Select Case Val(sBalance)
                    Case Is >= 100
                        .Items(vCnt).BackColor = Color.WhiteSmoke
                        .Items(vCnt).ForeColor = Color.Green
                    Case Is >= 1 'This works for money over 1000 if you have a "," position - (1,000.00)
                        .Items(vCnt).BackColor = Color.WhiteSmoke
                        .Items(vCnt).ForeColor = Color.Blue
                    Case 0
                        .Items(vCnt).BackColor = Color.WhiteSmoke
                        .Items(vCnt).ForeColor = Color.Magenta
                    Case Is < 0
                        .Items(vCnt).BackColor = Color.White
                        .Items(vCnt).ForeColor = Color.Red
                End Select
                Listview1.Items(vCnt).SubItems.Add(listArray(v).Substring(listArray(v).IndexOf(",") + 1, listArray(v).IndexOf("!") - listArray(v).IndexOf(",") - 1))
                Listview1.Items(vCnt).SubItems.Add(listArray(v).Substring(listArray(v).IndexOf("!") + 1, listArray(v).IndexOf(";") - listArray(v).IndexOf("!") - 1))
                Listview1.Items(vCnt).SubItems.Add(listArray(v).Substring(listArray(v).IndexOf(";") + 1))
                vCnt += 1
                v += 1
            End With
        Catch Exp As Exception
            MsgBox(Exp.Message, MsgBoxStyle.Critical, "Error Loading ListView Reports")
            Cursor.Current = Cursors.Default
        Finally
        End Try
    End Sub
 
    Private Sub Listview1_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles Listview1.ItemCheck
        Dim sTemp As String = sender.Items(e.Index).SubItems.Item(3).Text
        Dim sID As String = sender.Items(e.Index).SubItems.Item(0).Text
        Dim d As Integer
 
        If sID.IndexOfAny("'Edit Balance'") >= 0 Then
            sID = sID.Substring(0, sID.IndexOfAny("'Edit Balance'"))
        End If
 
        'Select only one item at a time
        'If e.CurrentValue = CheckState.Unchecked Then
        '    If Listview1.CheckedIndices.Count > 0 Then
        '        Dim itm As ListViewItem
        '        Listview1.SelectedItems().Clear()
        '        For Each itm In Listview1.CheckedItems
        '            itm.Checked = False
        '        Next
        '    End If
        'End If
 
        'Show progress of the checked boxes
        If e.CurrentValue = CheckState.Unchecked Then
            Listview1.Columns.RemoveAt(0)
            Listview1.Columns.Insert(0, "Paid", 130, HorizontalAlignment.Left)
            With sender
                .Items(e.Index).UseItemStyleForSubItems = False
                .Items(e.Index).SubItems.Item(0).Text = String.Empty
                .Items(e.Index).SubItems.Item(0).Text = sID & " 'Edit Balance' "
                .Items(e.Index).subitems.item(0).ForeColor = Color.Orange
                For d = 1 To 3
                    Select Case CType(sTemp, Integer)
                        Case 1
                            .Items(e.Index).SubItems.Item(d).BackColor = Color.WhiteSmoke
                            .Items(e.Index).SubItems.Item(d).ForeColor = Color.Green
                        Case 2 To 3
                            .Items(e.Index).SubItems.Item(d).BackColor = Color.WhiteSmoke
                            .Items(e.Index).SubItems.Item(d).ForeColor = Color.Blue
                        Case 4 To 9
                            .Items(e.Index).SubItems.Item(d).BackColor = Color.WhiteSmoke
                            .Items(e.Index).SubItems.Item(d).ForeColor = Color.Magenta
                        Case Is >= 10
                            .Items(e.Index).SubItems.Item(d).BackColor = Color.White
                            .Items(e.Index).SubItems.Item(d).ForeColor = Color.Red
                    End Select
                Next
                txtAdd.Text = .Items(e.Index).SubItems.Item(2).Text
                txtSubtract.Text = .Items(e.Index).SubItems.Item(3).Text
            End With
        Else
            If Listview1.CheckedIndices.Count <= 1 Then
                Listview1.Columns.RemoveAt(0)
                Listview1.Columns.Insert(0, "Paid", 60, HorizontalAlignment.Left)
            End If
            With sender
                Select Case CType(sTemp, Integer)
                    Case 0
                        .Items(e.Index).BackColor = Color.WhiteSmoke
                        .Items(e.Index).ForeColor = Color.Magenta
                    Case 1
                        .Items(e.Index).BackColor = Color.WhiteSmoke
                        .Items(e.Index).ForeColor = Color.Green
                    Case 2 To 3
                        .Items(e.Index).BackColor = Color.WhiteSmoke
                        .Items(e.Index).ForeColor = Color.Blue
                    Case 4 To 9
                        .Items(e.Index).BackColor = Color.WhiteSmoke
                        .Items(e.Index).ForeColor = Color.Magenta
                    Case Is >= 10
                        .Items(e.Index).BackColor = Color.White
                        .Items(e.Index).ForeColor = Color.Red
                End Select
                .Items(e.Index).SubItems.Item(0).Text = String.Empty
                .Items(e.Index).SubItems.Item(0).Text = sID
            End With
            txtAdd.Text = "0"
            txtSubtract.Text = "0"
        End If
 
        With sender
            Select Case .Items(e.Index).SubItems.Item(2).text
                Case Is >= 100
                    .Items(e.Index).SubItems.Item(2).BackColor = Color.WhiteSmoke
                    .Items(e.Index).SubItems.Item(2).ForeColor = Color.Green
                Case Is >= 1
                    .Items(e.Index).SubItems.Item(2).BackColor = Color.WhiteSmoke
                    .Items(e.Index).SubItems.Item(2).ForeColor = Color.Blue
                Case 0
                    .Items(e.Index).SubItems.Item(2).BackColor = Color.WhiteSmoke
                    .Items(e.Index).SubItems.Item(2).ForeColor = Color.Magenta
                Case Is < 0
                    .Items(e.Index).SubItems.Item(2).BackColor = Color.White
                    .Items(e.Index).SubItems.Item(2).ForeColor = Color.Red
            End Select
        End With
    End Sub
 
    Private Sub btnSubtract_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubtract.Click
        Dim item As ListViewItem = Nothing
        Dim Balance_Sub As Double = 0.0
        Dim checkedItems As ListView.CheckedListViewItemCollection = Listview1.CheckedItems
        For Each item In checkedItems
            Balance_Sub = Double.Parse(item.SubItems(3).Text) - txtSubtract.Text
        Next
        item.SubItems(3).Text = Format(Balance_Sub, "##,###.#0")
        Check_Balance(item)
    End Sub
 
    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim item As ListViewItem = Nothing
        Dim Balance_Add As Double = 0.0
        Dim checkedItems As ListView.CheckedListViewItemCollection = Listview1.CheckedItems
        For Each item In checkedItems
            If item.SubItems(3).Text > "0" Then
                Balance_Add = txtAdd.Text + Double.Parse(item.SubItems(3).Text)
            Else
                Balance_Add = txtAdd.Text + Double.Parse(item.SubItems(2).Text)
            End If
        Next
        item.SubItems(3).Text = Format(Balance_Add, "##,###.#0")
        Check_Balance(item)
    End Sub
 
    Private Sub Listview1_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles Listview1.ColumnClick
        ' Determine whether the column is the same as the last column clicked.
        If e.Column <> sortColumn Then
            ' Set the sort column to the new column.
            sortColumn = e.Column
            ' Set the sort order to ascending by default.
            Listview1.Sorting = SortOrder.Ascending
        Else
            ' Determine what the last sort order was and change it.
            If Listview1.Sorting = SortOrder.Ascending Then
                Listview1.Sorting = SortOrder.Descending
            Else
                Listview1.Sorting = SortOrder.Ascending
            End If
        End If
        ' Call the sort method to manually sort.
        Listview1.Sort()
        ' Set the ListViewItemSorter property to a new ListViewItemComparer object.
        Listview1.ListViewItemSorter = New ListViewItemComparer(e.Column, Listview1.Sorting)
    End Sub
 
    Private Sub Check_Balance(ByVal item As Object)
 
        Select Case CType(item.SubItems(3).Text, Integer)
            Case Is >= 100
                item.SubItems(3).BackColor = Color.WhiteSmoke
                item.SubItems(3).ForeColor = Color.Green
            Case Is >= 1
                item.SubItems(3).BackColor = Color.WhiteSmoke
                item.SubItems(3).ForeColor = Color.Blue
            Case 0
                item.SubItems(3).BackColor = Color.WhiteSmoke
                item.SubItems(3).ForeColor = Color.Magenta
            Case Is < 0
                item.SubItems(3).BackColor = Color.White
                item.SubItems(3).ForeColor = Color.Red
        End Select
    End Sub
 
    Private Sub btnPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPreview.Click
        Dim dlg As New PrintPreviewDialog()
        dlg.Document = mDoc
        dlg.WindowState = FormWindowState.Maximized
        dlg.ShowDialog()
    End Sub
    Private Sub mDoc_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles mDoc.PrintPage
        Dim checkedItems As ListView.CheckedListViewItemCollection = Listview1.CheckedItems
        Dim item As ListViewItem = Nothing
 
        Dim xPos As Single = e.MarginBounds.Left
        Dim lineHeight As Single = mFont.GetHeight(e.Graphics)
        Dim font As New Font("Microsoft Sans Serif", 10)
 
        Dim linesPerPage As Single = 0
        Dim yPos As Single = 0
        Dim count As Integer = 0
        Dim leftMargin As Single = e.MarginBounds.Left
        Dim topMargin As Single = e.MarginBounds.Top
        Dim line As String = Nothing
 
        'Define the Company Header Position
        x1 = 35 : y1 = 30 ' Company Name
        x2 = 35 : y2 = 45 ' Address 1
        x3 = 35 : y3 = 60 ' Address 2
        x4 = 35 : y4 = 75 ' City/State/Zip
 
        x5 = 678 : y5 = 68  ' Date
        x6 = 110 : y6 = 120 'John Doe y is up and down, x is left and right
        x7 = 675 : y7 = 120 'Amount Box
        x8 = 42 : y8 = 150  'Money String.
        x9 = 90 : y9 = 185  'For Line
        x10 = 90 : y10 = 185  'For Line
 
        ' Calculate the number of lines per page.
        linesPerPage = CInt(e.MarginBounds.Height / lineHeight)
 
        Dim CoName As String = "CoName"
        Dim Address1 As String = "Address1 "
        Dim Address2 As String = "Address2 "
        Dim CityStateZip As String = "CityStateZip "
        Dim ForLine As String = " ForLine"
 
        'Start the Loop
        While count < linesPerPage
            For Each item In checkedItems
                Col1 = item.SubItems(1).Text 'Get the Consignor Name
                Col2 = item.SubItems(2).Text
                Col2Parsed = Col2.Substring(1)
                'Process the text String for Dollar Amount
                'convert the text into a decimal
                decAmount = Col2 'Convert.ToDecimal(Col2Parsed)
 
                'set the number of decimal places to 2
                decAmount = Decimal.Round(decAmount, 2)
                'Add the Amounts
                decAmount2 += decAmount
 
                strAmount = decAmount2.ToString
 
                yPos += lineHeight
                ' yPos = topMargin + count * printFont
 
                'write the returned string out onto the check
                With e.Graphics
                    .DrawString(CoName, font, Brushes.Black, x1, y1)
                    .DrawString(Address1, font, Brushes.Black, x2, y2)
                    .DrawString(Address2, font, Brushes.Black, x3, y3)
                    .DrawString(CityStateZip, font, Brushes.Black, x4, y4)
 
                    'write the returned string out onto the check
                    .DrawString(ShortDate, font, Brushes.Black, x5, y5)
                    .DrawString(Col1, font, Brushes.Black, x6, y6)
                    .DrawString(Col2.ToString, font, Brushes.Black, x7, y7)
                    .DrawString(strAmount, font, Brushes.Black, x8, y8)
                    .DrawString(ForLine, font, Brushes.Black, x9, y9)
                    .DrawString(ForLine, font, Brushes.Black, x10, y10)
                    .DrawString("* * * * * * * * * * * * * * * * * * * * * * * *", font, Brushes.Black, x8 + 360, y8 + 4)
                End With
                ' HasMorePages tells the printing module whether another PrintPage event
                ' should be fired.
 
                'Change print position on page
                Const px As Integer = 350
 
                y1 += px
                y2 += px
                y3 += px
                y4 += px
                y5 += px
                y6 += px
                y7 += px
                y8 += px
                y9 += px
                y10 += px
                count += 19
                Y += 1
            Next
        End While
        If Y < 40 Then
            e.HasMorePages = True
        Else
            e.HasMorePages = False
        End If
 
    End Sub
End Class
 
'CLASS
 
' Implements the manual sorting of items by columns.
Class ListViewItemComparer
    Implements IComparer
    Private col As Integer
    Private order As SortOrder
 
    Public Sub New()
        col = 0
        order = SortOrder.Ascending
    End Sub
    Public Sub New(ByVal column As Integer, ByVal order As SortOrder)
        col = column
        Me.order = order
    End Sub
    Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer _
                        Implements System.Collections.IComparer.Compare
        Dim returnVal As Integer = -1
        returnVal = [String].Compare(CType(x, ListViewItem).SubItems(col).Text, _
                        CType(y, ListViewItem).SubItems(col).Text)
        ' Determine whether the sort order is descending.
        If order = SortOrder.Descending Then
            ' Invert the value returned by String.Compare.
            returnVal *= -1
        End If
        Return returnVal
    End Function
End Class

Open in new window

0
 
LVL 27

Expert Comment

by:planocz
ID: 21807445
Sorry I found an error in my code
please change.....
comment out the While loop , the count +=19, and replace  If Y < 40 Then with
If Y < checkedItems.Count then
0
 
LVL 1

Author Closing Comment

by:wsenter
ID: 31467749
You are the man! Thanks.  This will help a great deal.
0
 
LVL 1

Author Comment

by:wsenter
ID: 21829072
planocz,

The fix you suggested in your last post does not work. It prints the first page only with partial 4th check at bottom of form.
0
 
LVL 27

Expert Comment

by:planocz
ID: 21831433
I did not like the way the solution was running so I retested it .
It may still have some bugs but I think it is close.
Good luck on your project

'FORM 1 DESIGNER
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class frmViewChecks
    Inherits System.Windows.Forms.Form
 
    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub
 
    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer
 
    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.CheckBox3 = New System.Windows.Forms.CheckBox
        Me.CheckBox2 = New System.Windows.Forms.CheckBox
        Me.CheckBox1 = New System.Windows.Forms.CheckBox
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.btnAdd = New System.Windows.Forms.Button
        Me.btnSubtract = New System.Windows.Forms.Button
        Me.txtSubtract = New System.Windows.Forms.TextBox
        Me.txtAdd = New System.Windows.Forms.TextBox
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.PictureBox2 = New System.Windows.Forms.PictureBox
        Me.lblGreen = New System.Windows.Forms.Label
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.lblTotalcnt = New System.Windows.Forms.Label
        Me.lblMagenta = New System.Windows.Forms.Label
        Me.PictureBox4 = New System.Windows.Forms.PictureBox
        Me.lblRed = New System.Windows.Forms.Label
        Me.PictureBox3 = New System.Windows.Forms.PictureBox
        Me.lblBlue = New System.Windows.Forms.Label
        Me.Listview1 = New System.Windows.Forms.ListView
        Me.btnPreView = New System.Windows.Forms.Button
        Me.btnClose = New System.Windows.Forms.Button
        Me.GroupBox1.SuspendLayout()
        Me.Panel1.SuspendLayout()
        CType(Me.PictureBox2, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.PictureBox4, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.PictureBox3, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'CheckBox3
        '
        Me.CheckBox3.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.CheckBox3.Location = New System.Drawing.Point(328, 38)
        Me.CheckBox3.Name = "CheckBox3"
        Me.CheckBox3.Size = New System.Drawing.Size(230, 20)
        Me.CheckBox3.TabIndex = 34
        Me.CheckBox3.Text = "Delete all Checks and Highlights"
        '
        'CheckBox2
        '
        Me.CheckBox2.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.CheckBox2.Location = New System.Drawing.Point(216, 38)
        Me.CheckBox2.Name = "CheckBox2"
        Me.CheckBox2.Size = New System.Drawing.Size(92, 20)
        Me.CheckBox2.TabIndex = 33
        Me.CheckBox2.Text = "Select All"
        '
        'CheckBox1
        '
        Me.CheckBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.CheckBox1.Location = New System.Drawing.Point(8, 38)
        Me.CheckBox1.Name = "CheckBox1"
        Me.CheckBox1.Size = New System.Drawing.Size(196, 20)
        Me.CheckBox1.TabIndex = 32
        Me.CheckBox1.Text = "Clear all Checks and Highlights"
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.btnAdd)
        Me.GroupBox1.Controls.Add(Me.btnSubtract)
        Me.GroupBox1.Controls.Add(Me.txtSubtract)
        Me.GroupBox1.Controls.Add(Me.txtAdd)
        Me.GroupBox1.Controls.Add(Me.Panel1)
        Me.GroupBox1.Controls.Add(Me.Listview1)
        Me.GroupBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.GroupBox1.Location = New System.Drawing.Point(8, 78)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(699, 358)
        Me.GroupBox1.TabIndex = 31
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Test Balance"
        '
        'btnAdd
        '
        Me.btnAdd.Location = New System.Drawing.Point(24, 289)
        Me.btnAdd.Name = "btnAdd"
        Me.btnAdd.Size = New System.Drawing.Size(69, 27)
        Me.btnAdd.TabIndex = 31
        Me.btnAdd.Text = "Add"
        Me.btnAdd.UseVisualStyleBackColor = True
        '
        'btnSubtract
        '
        Me.btnSubtract.Location = New System.Drawing.Point(203, 292)
        Me.btnSubtract.Name = "btnSubtract"
        Me.btnSubtract.Size = New System.Drawing.Size(69, 27)
        Me.btnSubtract.TabIndex = 30
        Me.btnSubtract.Text = "Subtract"
        Me.btnSubtract.UseVisualStyleBackColor = True
        '
        'txtSubtract
        '
        Me.txtSubtract.Location = New System.Drawing.Point(278, 296)
        Me.txtSubtract.Name = "txtSubtract"
        Me.txtSubtract.Size = New System.Drawing.Size(69, 20)
        Me.txtSubtract.TabIndex = 29
        Me.txtSubtract.Text = "0"
        '
        'txtAdd
        '
        Me.txtAdd.Location = New System.Drawing.Point(99, 295)
        Me.txtAdd.Name = "txtAdd"
        Me.txtAdd.Size = New System.Drawing.Size(69, 20)
        Me.txtAdd.TabIndex = 28
        Me.txtAdd.Text = "0"
        '
        'Panel1
        '
        Me.Panel1.Controls.Add(Me.PictureBox2)
        Me.Panel1.Controls.Add(Me.lblGreen)
        Me.Panel1.Controls.Add(Me.PictureBox1)
        Me.Panel1.Controls.Add(Me.lblTotalcnt)
        Me.Panel1.Controls.Add(Me.lblMagenta)
        Me.Panel1.Controls.Add(Me.PictureBox4)
        Me.Panel1.Controls.Add(Me.lblRed)
        Me.Panel1.Controls.Add(Me.PictureBox3)
        Me.Panel1.Controls.Add(Me.lblBlue)
        Me.Panel1.Location = New System.Drawing.Point(4, 15)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(669, 32)
        Me.Panel1.TabIndex = 25
        '
        'PictureBox2
        '
        Me.PictureBox2.BackColor = System.Drawing.Color.Blue
        Me.PictureBox2.Location = New System.Drawing.Point(144, 8)
        Me.PictureBox2.Name = "PictureBox2"
        Me.PictureBox2.Size = New System.Drawing.Size(16, 12)
        Me.PictureBox2.TabIndex = 2
        Me.PictureBox2.TabStop = False
        '
        'lblGreen
        '
        Me.lblGreen.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblGreen.Location = New System.Drawing.Point(28, 8)
        Me.lblGreen.Name = "lblGreen"
        Me.lblGreen.Size = New System.Drawing.Size(122, 16)
        Me.lblGreen.TabIndex = 1
        Me.lblGreen.Text = "Green - Plus Balance"
        '
        'PictureBox1
        '
        Me.PictureBox1.BackColor = System.Drawing.Color.SeaGreen
        Me.PictureBox1.Location = New System.Drawing.Point(4, 8)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(16, 12)
        Me.PictureBox1.TabIndex = 0
        Me.PictureBox1.TabStop = False
        '
        'lblTotalcnt
        '
        Me.lblTotalcnt.Location = New System.Drawing.Point(632, 8)
        Me.lblTotalcnt.Name = "lblTotalcnt"
        Me.lblTotalcnt.Size = New System.Drawing.Size(28, 16)
        Me.lblTotalcnt.TabIndex = 24
        '
        'lblMagenta
        '
        Me.lblMagenta.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblMagenta.Location = New System.Drawing.Point(325, 8)
        Me.lblMagenta.Name = "lblMagenta"
        Me.lblMagenta.Size = New System.Drawing.Size(124, 16)
        Me.lblMagenta.TabIndex = 8
        Me.lblMagenta.Text = "Magenta- Zero Balance"
        '
        'PictureBox4
        '
        Me.PictureBox4.BackColor = System.Drawing.Color.Magenta
        Me.PictureBox4.Location = New System.Drawing.Point(306, 8)
        Me.PictureBox4.Name = "PictureBox4"
        Me.PictureBox4.Size = New System.Drawing.Size(16, 12)
        Me.PictureBox4.TabIndex = 7
        Me.PictureBox4.TabStop = False
        '
        'lblRed
        '
        Me.lblRed.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblRed.Location = New System.Drawing.Point(481, 8)
        Me.lblRed.Name = "lblRed"
        Me.lblRed.Size = New System.Drawing.Size(140, 16)
        Me.lblRed.TabIndex = 5
        Me.lblRed.Text = "Red - Negative Balance"
        '
        'PictureBox3
        '
        Me.PictureBox3.BackColor = System.Drawing.Color.Red
        Me.PictureBox3.Location = New System.Drawing.Point(457, 8)
        Me.PictureBox3.Name = "PictureBox3"
        Me.PictureBox3.Size = New System.Drawing.Size(16, 12)
        Me.PictureBox3.TabIndex = 4
        Me.PictureBox3.TabStop = False
        '
        'lblBlue
        '
        Me.lblBlue.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblBlue.Location = New System.Drawing.Point(166, 8)
        Me.lblBlue.Name = "lblBlue"
        Me.lblBlue.Size = New System.Drawing.Size(138, 12)
        Me.lblBlue.TabIndex = 3
        Me.lblBlue.Text = "Blue- Over 1,000 Balance"
        '
        'Listview1
        '
        Me.Listview1.AllowColumnReorder = True
        Me.Listview1.CheckBoxes = True
        Me.Listview1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Listview1.FullRowSelect = True
        Me.Listview1.GridLines = True
        Me.Listview1.Location = New System.Drawing.Point(11, 52)
        Me.Listview1.MultiSelect = False
        Me.Listview1.Name = "Listview1"
        Me.Listview1.Size = New System.Drawing.Size(657, 224)
        Me.Listview1.TabIndex = 6
        Me.Listview1.UseCompatibleStateImageBehavior = False
        Me.Listview1.View = System.Windows.Forms.View.Details
        '
        'btnPreView
        '
        Me.btnPreView.Location = New System.Drawing.Point(601, 20)
        Me.btnPreView.Name = "btnPreView"
        Me.btnPreView.Size = New System.Drawing.Size(75, 23)
        Me.btnPreView.TabIndex = 35
        Me.btnPreView.Text = "Print View"
        Me.btnPreView.UseVisualStyleBackColor = True
        '
        'btnClose
        '
        Me.btnClose.Location = New System.Drawing.Point(601, 49)
        Me.btnClose.Name = "btnClose"
        Me.btnClose.Size = New System.Drawing.Size(75, 23)
        Me.btnClose.TabIndex = 36
        Me.btnClose.Text = "Close"
        Me.btnClose.UseVisualStyleBackColor = True
        '
        'frmViewChecks
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(720, 446)
        Me.Controls.Add(Me.btnClose)
        Me.Controls.Add(Me.btnPreView)
        Me.Controls.Add(Me.CheckBox3)
        Me.Controls.Add(Me.CheckBox2)
        Me.Controls.Add(Me.CheckBox1)
        Me.Controls.Add(Me.GroupBox1)
        Me.Name = "frmViewChecks"
        Me.Text = "Form1"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox1.PerformLayout()
        Me.Panel1.ResumeLayout(False)
        CType(Me.PictureBox2, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.PictureBox4, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.PictureBox3, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
 
    End Sub
    Friend WithEvents CheckBox3 As System.Windows.Forms.CheckBox
    Friend WithEvents CheckBox2 As System.Windows.Forms.CheckBox
    Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents btnAdd As System.Windows.Forms.Button
    Friend WithEvents btnSubtract As System.Windows.Forms.Button
    Friend WithEvents txtSubtract As System.Windows.Forms.TextBox
    Friend WithEvents txtAdd As System.Windows.Forms.TextBox
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents PictureBox2 As System.Windows.Forms.PictureBox
    Friend WithEvents lblGreen As System.Windows.Forms.Label
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents lblTotalcnt As System.Windows.Forms.Label
    Friend WithEvents lblMagenta As System.Windows.Forms.Label
    Friend WithEvents PictureBox4 As System.Windows.Forms.PictureBox
    Friend WithEvents lblRed As System.Windows.Forms.Label
    Friend WithEvents PictureBox3 As System.Windows.Forms.PictureBox
    Friend WithEvents lblBlue As System.Windows.Forms.Label
    Friend WithEvents Listview1 As System.Windows.Forms.ListView
    Friend WithEvents btnPreView As System.Windows.Forms.Button
    Friend WithEvents btnClose As System.Windows.Forms.Button
 
End Class
 
'FORM 1
Imports System.Drawing
Imports System.Drawing.Printing
Public Class frmViewChecks
 
    Private vCnt As Integer = 0
    Private v As Integer = 0
    Private sortColumn As Integer = -1
    Private iCounter As Integer = 0
    Private x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12 As Integer
    Private iItemCountTot As Integer = 0
    Private linesPerPage As Single = 0
    Private decAmount As Decimal
    Private decAmountADD As Decimal
 
    Private arrID() As String
    Private Col1 As String = String.Empty
    Private Col2 As String = String.Empty
    Private strAmount As String = String.Empty
    Private ShortDate As String = Now.ToString("d")
 
    Private WithEvents mDoc As New PrintDocument()
    Private mFont As New Font("Courier New", 12)
 
    Private WithEvents PrintDoc1 As New Print_Cks_Listview.PrintDoc
 
    Private Sub Form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        InitializeListView()
    End Sub
    Private Sub InitializeListView()
        With Listview1
            .Columns.Add("Company ID", 100, HorizontalAlignment.Left)
            .Columns.Add("Company Name", 150, HorizontalAlignment.Left)
            .Columns.Add("Current Balance", 150, HorizontalAlignment.Left)
            .Columns.Add("New Balance", 150, HorizontalAlignment.Left)
        End With
        ReDim arrID(10)
        'FOR TESTING ONLY
        'STRING ARRAY ---- ID & "," & Company Name & "!" & Current Balance & ";" & New Balance   
        arrID(0) = "ID1" & "," & "Company Name1" & "!" & "1,000.00" & ";" & "0"
        arrID(1) = "ID2" & "," & "Company Name2" & "!" & "548.00" & ";" & "0"
        arrID(2) = "ID3" & "," & "Company Name3" & "!" & "225.84" & ";" & "0"
        arrID(3) = "ID4" & "," & "Company Name4" & "!" & "23,168.40" & ";" & "0"
        arrID(4) = "ID5" & "," & "Company Name5" & "!" & "2,383.00" & ";" & "0"
        arrID(5) = "ID6" & "," & "Company Name6" & "!" & "315.00" & ";" & "0"
        arrID(6) = "ID7" & "," & "Company Name7" & "!" & "948.00" & ";" & "0"
        arrID(7) = "ID8" & "," & "Company Name8" & "!" & "266.00" & ";" & "0"
        arrID(8) = "ID9" & "," & "Company Name9" & "!" & "587.00" & ";" & "0"
        arrID(9) = "ID10" & "," & "Company Name10" & "!" & "4,884.00" & ";" & "0"
        For iCounter = 0 To 9
            LoadListView(arrID)
        Next
        'Reset counter back to zero
        'because with use it elsewhere
        iCounter = 0
    End Sub
#Region " Checkbox Changes "
    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked = True Then
            Dim itm As ListViewItem
            Listview1.SelectedItems().Clear()
            For Each itm In Listview1.CheckedItems
                itm.Checked = False
            Next
            CheckBox1.Checked = False
            CheckBox2.Checked = False
        End If
    End Sub
    Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
        If CheckBox2.Checked = True Then
            Dim itm As ListViewItem
            For Each itm In Listview1.Items
                itm.Checked = True
            Next
        End If
    End Sub
    Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
        If CheckBox3.Checked = True Then
            Cursor.Current = Cursors.WaitCursor
            Dim itm As ListViewItem
            Listview1.SelectedItems().Clear()
            For Each itm In Listview1.CheckedItems
                itm.Remove()
            Next
            For Each itm In Listview1.SelectedItems
                itm.Remove()
            Next
            CheckBox3.CheckState = CheckState.Unchecked
            lblTotalcnt.Text = Listview1.Items.Count
            Listview1.Refresh()
            lblTotalcnt.Refresh()
        End If
    End Sub
#End Region
    Private Sub Check_Balance(ByVal item As Object)
 
        Select Case CType(item.SubItems(3).Text, Integer)
            Case Is >= 100
                item.SubItems(3).BackColor = Color.WhiteSmoke
                item.SubItems(3).ForeColor = Color.Green
            Case Is >= 1
                item.SubItems(3).BackColor = Color.WhiteSmoke
                item.SubItems(3).ForeColor = Color.Blue
            Case 0
                item.SubItems(3).BackColor = Color.WhiteSmoke
                item.SubItems(3).ForeColor = Color.Magenta
            Case Is < 0
                item.SubItems(3).BackColor = Color.White
                item.SubItems(3).ForeColor = Color.Red
        End Select
    End Sub
    Private Sub LoadListView(ByVal listArray() As String)
        Dim sID As String
        Dim sBalance As String
 
        Try
            'INCOMING STRING ARRAY ---- ID & "," & Company Name & "!" & Current Balance & ";" & New Balance      
            sID = listArray(v).Substring(0, listArray(v).IndexOf(",") - listArray(v).IndexOf("|") - 1)
            sBalance = listArray(v).Substring(listArray(v).IndexOf("!") + 1, listArray(v).IndexOf(";") - listArray(v).IndexOf("!") - 1)
            With Listview1
                .Items.Add(sID)
                Select Case Val(sBalance)
                    Case Is >= 100
                        .Items(vCnt).BackColor = Color.WhiteSmoke
                        .Items(vCnt).ForeColor = Color.Green
                    Case Is >= 1 'This works for money over 1000 if you have a "," position - (1,000.00)
                        .Items(vCnt).BackColor = Color.WhiteSmoke
                        .Items(vCnt).ForeColor = Color.Blue
                    Case 0
                        .Items(vCnt).BackColor = Color.WhiteSmoke
                        .Items(vCnt).ForeColor = Color.Magenta
                    Case Is < 0
                        .Items(vCnt).BackColor = Color.White
                        .Items(vCnt).ForeColor = Color.Red
                End Select
                Listview1.Items(vCnt).SubItems.Add(listArray(v).Substring(listArray(v).IndexOf(",") + 1, listArray(v).IndexOf("!") - listArray(v).IndexOf(",") - 1))
                Listview1.Items(vCnt).SubItems.Add(listArray(v).Substring(listArray(v).IndexOf("!") + 1, listArray(v).IndexOf(";") - listArray(v).IndexOf("!") - 1))
                Listview1.Items(vCnt).SubItems.Add(listArray(v).Substring(listArray(v).IndexOf(";") + 1))
                vCnt += 1
                v += 1
            End With
        Catch Exp As Exception
            MsgBox(Exp.Message, MsgBoxStyle.Critical, "Error Loading ListView Reports")
            Cursor.Current = Cursors.Default
        Finally
        End Try
    End Sub
 
    Private Sub Listview1_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles Listview1.ItemCheck
        Dim sTemp As String = sender.Items(e.Index).SubItems.Item(3).Text
        Dim sID As String = sender.Items(e.Index).SubItems.Item(0).Text
        Dim d As Integer
 
        If sID.IndexOfAny("'Edit Balance'") >= 0 Then
            sID = sID.Substring(0, sID.IndexOfAny("'Edit Balance'"))
            sID &= " Printed"
        End If
 
        'Select only one item at a time
        'If e.CurrentValue = CheckState.Unchecked Then
        '    If Listview1.CheckedIndices.Count > 0 Then
        '        Dim itm As ListViewItem
        '        Listview1.SelectedItems().Clear()
        '        For Each itm In Listview1.CheckedItems
        '            itm.Checked = False
        '        Next
        '    End If
        'End If
 
        'Show progress of the checked boxes
        If e.CurrentValue = CheckState.Unchecked Then
            Listview1.Columns.RemoveAt(0)
            Listview1.Columns.Insert(0, "Edit Print", 130, HorizontalAlignment.Left)
            With sender
                .Items(e.Index).UseItemStyleForSubItems = False
                .Items(e.Index).SubItems.Item(0).Text = String.Empty
                .Items(e.Index).SubItems.Item(0).Text = sID & " 'Edit Balance' "
                .Items(e.Index).subitems.item(0).ForeColor = Color.Orange
                For d = 1 To 3
                    Select Case CType(sTemp, Integer)
                        Case 1
                            .Items(e.Index).SubItems.Item(d).BackColor = Color.WhiteSmoke
                            .Items(e.Index).SubItems.Item(d).ForeColor = Color.Green
                        Case 2 To 3
                            .Items(e.Index).SubItems.Item(d).BackColor = Color.WhiteSmoke
                            .Items(e.Index).SubItems.Item(d).ForeColor = Color.Blue
                        Case 4 To 9
                            .Items(e.Index).SubItems.Item(d).BackColor = Color.WhiteSmoke
                            .Items(e.Index).SubItems.Item(d).ForeColor = Color.Magenta
                        Case Is >= 10
                            .Items(e.Index).SubItems.Item(d).BackColor = Color.White
                            .Items(e.Index).SubItems.Item(d).ForeColor = Color.Red
                    End Select
                Next
                txtAdd.Text = .Items(e.Index).SubItems.Item(2).Text
                txtSubtract.Text = .Items(e.Index).SubItems.Item(3).Text
            End With
        Else
            If Listview1.CheckedIndices.Count <= 1 Then
                Listview1.Columns.RemoveAt(0)
                Listview1.Columns.Insert(0, "Printed", 110, HorizontalAlignment.Left)
            End If
            With sender
                .Items(e.Index).UseItemStyleForSubItems = False
                .Items(e.Index).SubItems.Item(0).Text = String.Empty
                .Items(e.Index).SubItems.Item(0).Text = sID
                .Items(e.Index).subitems.item(0).ForeColor = Color.Purple
                Select Case CType(sTemp, Integer)
                    Case 0
                        .Items(e.Index).BackColor = Color.WhiteSmoke
                        .Items(e.Index).ForeColor = Color.Magenta
                    Case 1
                        .Items(e.Index).BackColor = Color.WhiteSmoke
                        .Items(e.Index).ForeColor = Color.Green
                    Case 2 To 3
                        .Items(e.Index).BackColor = Color.WhiteSmoke
                        .Items(e.Index).ForeColor = Color.Blue
                    Case 4 To 9
                        .Items(e.Index).BackColor = Color.WhiteSmoke
                        .Items(e.Index).ForeColor = Color.Magenta
                    Case Is >= 10
                        .Items(e.Index).BackColor = Color.White
                        .Items(e.Index).ForeColor = Color.Red
                End Select
                .Items(e.Index).SubItems.Item(0).Text = String.Empty
                .Items(e.Index).SubItems.Item(0).Text = sID
            End With
            txtAdd.Text = "0"
            txtSubtract.Text = "0"
        End If
 
        With sender
            Select Case .Items(e.Index).SubItems.Item(2).text
                Case Is >= 100
                    .Items(e.Index).SubItems.Item(2).BackColor = Color.WhiteSmoke
                    .Items(e.Index).SubItems.Item(2).ForeColor = Color.Green
                Case Is >= 1
                    .Items(e.Index).SubItems.Item(2).BackColor = Color.WhiteSmoke
                    .Items(e.Index).SubItems.Item(2).ForeColor = Color.Blue
                Case 0
                    .Items(e.Index).SubItems.Item(2).BackColor = Color.WhiteSmoke
                    .Items(e.Index).SubItems.Item(2).ForeColor = Color.Magenta
                Case Is < 0
                    .Items(e.Index).SubItems.Item(2).BackColor = Color.White
                    .Items(e.Index).SubItems.Item(2).ForeColor = Color.Red
            End Select
        End With
    End Sub
 
#Region "Button/Listview Clicks"
    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub
    Private Sub btnSubtract_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubtract.Click
        Dim item As ListViewItem = Nothing
        Dim Balance_Sub As Double = 0.0
        Dim checkedItems As ListView.CheckedListViewItemCollection = Listview1.CheckedItems
        For Each item In checkedItems
            Balance_Sub = Double.Parse(item.SubItems(3).Text) - txtSubtract.Text
        Next
        item.SubItems(3).Text = Format(Balance_Sub, "##,###.#0")
        Check_Balance(item)
    End Sub
    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim item As ListViewItem = Nothing
        Dim Balance_Add As Double = 0.0
        Dim checkedItems As ListView.CheckedListViewItemCollection = Listview1.CheckedItems
        For Each item In checkedItems
            If item.SubItems(3).Text > "0" Then
                Balance_Add = txtAdd.Text + Double.Parse(item.SubItems(3).Text)
            Else
                Balance_Add = txtAdd.Text + Double.Parse(item.SubItems(2).Text)
            End If
        Next
        item.SubItems(3).Text = Format(Balance_Add, "##,###.#0")
        Check_Balance(item)
    End Sub
    Private Sub Listview1_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles Listview1.ColumnClick
        ' Determine whether the column is the same as the last column clicked.
        If e.Column <> sortColumn Then
            ' Set the sort column to the new column.
            sortColumn = e.Column
            ' Set the sort order to ascending by default.
            Listview1.Sorting = SortOrder.Ascending
        Else
            ' Determine what the last sort order was and change it.
            If Listview1.Sorting = SortOrder.Ascending Then
                Listview1.Sorting = SortOrder.Descending
            Else
                Listview1.Sorting = SortOrder.Ascending
            End If
        End If
        ' Call the sort method to manually sort.
        Listview1.Sort()
        ' Set the ListViewItemSorter property to a new ListViewItemComparer object.
        Listview1.ListViewItemSorter = New ListViewItemComparer(e.Column, Listview1.Sorting)
    End Sub
    Private Sub btnPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPreView.Click
        Dim checkedItems As ListView.CheckedListViewItemCollection = Listview1.CheckedItems
        If checkedItems.Count = 0 Then Exit Sub
 
        Dim dlg As New PrintPreviewDialog()
        dlg.Document = mDoc
        dlg.WindowState = FormWindowState.Maximized
        dlg.ShowDialog()
    End Sub
#End Region
 
    Private Sub Doc_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles mDoc.PrintPage
        Dim yPos As Single = e.MarginBounds.Top
        Dim xPos As Single = e.MarginBounds.Left
        Dim bottomMargin As Single = e.MarginBounds.Bottom
        Dim lineHeight As Single = mFont.GetHeight(e.Graphics)
        Dim font As New Font("Microsoft Sans Serif", 10)
 
        Dim checkedItems As ListView.CheckedListViewItemCollection = Listview1.CheckedItems
        Dim item As ListViewItem = Nothing
        iItemCountTot = checkedItems.Count
 
        'Define the Company Header Position
        x1 = 35  ' Company Name
        x2 = 35  ' Address 1
        x3 = 35  ' Address 2
        x4 = 35  ' City/State/Zip
 
        x5 = 678  ' Date
        x6 = 110  'John Doe y is up and down, x is left and right
        x7 = 675  'Amount Box
        x8 = 42   'Money String.
        x9 = 90   'For Line
        x10 = 90  'For Line
        x11 = 90
        x12 = 90
 
        ' Calculate the number of lines per page.
        linesPerPage = CInt(e.MarginBounds.Height / lineHeight)
 
        Dim CoName As String = "CoName"
        Dim Address1 As String = "Address1 "
        Dim Address2 As String = "Address2 "
        Dim CityStateZip As String = "CityStateZip "
        Dim ForLine As String = " ForLine"
 
        'Start the Loop
        For Each item In checkedItems
            If iItemCountTot > 3 Then e.HasMorePages = True Else e.HasMorePages = False
            If iCounter = 3 Then Exit For
            Col1 = item.SubItems(1).Text 'Get the Name
            Col2 = item.SubItems(2).Text 'Get the Balance
            decAmount = Convert.ToDecimal(Col2)
            decAmount = Decimal.Round(decAmount, 2)
            decAmountADD += decAmount
            strAmount = Format(decAmountADD, "##,###.00").ToString
 
            'write the returned string out onto the check
            With e.Graphics
                .DrawString(CoName, font, Brushes.Black, x1, yPos)
                yPos += lineHeight
                .DrawString(Address1, font, Brushes.Black, x2, yPos)
                yPos += lineHeight
                .DrawString(Address2, font, Brushes.Black, x3, yPos)
                yPos += lineHeight
                .DrawString(CityStateZip, font, Brushes.Black, x4, yPos)
                yPos += lineHeight
                'write the returned string out onto the check
                yPos += lineHeight
                .DrawString(ShortDate, font, Brushes.Black, x5, yPos)
                yPos += lineHeight
                .DrawString(Col1, font, Brushes.Black, x6, yPos)
                yPos += lineHeight
                .DrawString(Col2, font, Brushes.Black, x7, yPos)
                yPos += lineHeight
                .DrawString("* * * * * * * * * * * * * * * * * * * * * * * *", font, Brushes.Black, x8 + 360, yPos)
                yPos += lineHeight
                .DrawString(strAmount, font, Brushes.Black, x8, yPos)
                yPos += lineHeight
                .DrawString(ForLine, font, Brushes.Black, x9, yPos)
                yPos += lineHeight
                .DrawString(ForLine, font, Brushes.Black, x10, yPos)
                yPos += lineHeight
                .DrawString(" ", font, Brushes.Black, x11, yPos)
                yPos += lineHeight
                .DrawString(" ", font, Brushes.Black, x12, yPos)
            End With
            yPos += e.MarginBounds.Top
            iCounter += 1
        Next
        For Each item In Listview1.CheckedItems
            If item.Text.IndexOfAny("Printed") >= 0 Then
                item.Checked = False
            End If
            Select Case item.Index
                Case 2, 5, 8, 11, 14, 17, 20
                    Exit For
            End Select
        Next
        iCounter = 0
        Listview1.Columns.Item(0).Text = "Company ID"
        Listview1.Columns.Item(0).Width = 100
    End Sub
 
    'Private Sub PrintDoc1_PrintPages(ByVal Sender As Object, ByRef e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDoc1.PrintPages
 
    '    e.Graphics.DrawString("Hello", New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 100, 100)
    '    PrintDoc1.NextPage()
    '    e.Graphics.DrawString("Hello Again", New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 100, 100)
 
    'End Sub
 
End Class
 
'CLASS
' Implements the manual sorting of items by columns.
Class ListViewItemComparer
    Implements IComparer
    Private col As Integer
    Private order As SortOrder
 
    Public Sub New()
        col = 0
        order = SortOrder.Ascending
    End Sub
    Public Sub New(ByVal column As Integer, ByVal order As SortOrder)
        col = column
        Me.order = order
    End Sub
    Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer _
                        Implements System.Collections.IComparer.Compare
        Dim returnVal As Integer = -1
        returnVal = [String].Compare(CType(x, ListViewItem).SubItems(col).Text, _
                        CType(y, ListViewItem).SubItems(col).Text)
        ' Determine whether the sort order is descending.
        If order = SortOrder.Descending Then
            ' Invert the value returned by String.Compare.
            returnVal *= -1
        End If
        Return returnVal
    End Function
End Class

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question