1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| Imports System
Imports System.Data
Imports System.Data.OleDb
Imports Microsoft.VisualBasic
Imports System.Drawing.Printing
Public Class Form1
Inherits System.Windows.Forms.Form
Class ListViewItemComparer
Implements IComparer
Private col As Integer
Private sortOrder As SortOrder
Public Sub New()
col = 0
sortOrder = Windows.Forms.SortOrder.Ascending
End Sub
Public Sub New(ByVal column As Integer)
col = column
sortOrder = Windows.Forms.SortOrder.Ascending
End Sub
Public Sub New(ByVal column As Integer, ByVal s As SortOrder)
col = column
sortOrder = s
End Sub
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements IComparer.Compare
If sortOrder = Windows.Forms.SortOrder.Ascending Then
Return String.Compare(CType(x, ListViewItem).SubItems(col).Text, CType(y, ListViewItem).SubItems(col).Text)
Else
Return String.Compare(CType(y, ListViewItem).SubItems(col).Text, CType(x, ListViewItem).SubItems(col).Text)
End If
End Function
End Class
Public Function Init_SansPhoto()
ListViewActeurs.Items.Clear()
ListViewActeurs.Columns.Clear()
Me.ListViewActeurs.ListViewItemSorter = Nothing
Dim MyConnexion As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & _
"C:\Access\DvdData.mdb")
Dim Mycommand As OleDbCommand = MyConnexion.CreateCommand()
Mycommand.CommandText = "SELECT N°,Code FROM Acteurs WHERE AbscencePhoto = True ORDER BY Code"
MyConnexion.Open()
Dim myReader As OleDbDataReader = Mycommand.ExecuteReader()
ListViewActeurs.View = View.Details
With ListViewActeurs.Columns
.Add("N°", 45, HorizontalAlignment.Left)
.Add("Acteurs et actrices", 320, HorizontalAlignment.Left)
End With
Do While myReader.Read()
Dim _MyListViewItem As ListViewItem = New ListViewItem(Format(myReader.GetValue(0), "0000"))
With _MyListViewItem
.SubItems.Add(myReader.GetValue(1).ToString)
End With
ListViewActeurs.Items.Add(_MyListViewItem)
Loop
myReader.Close()
MyConnexion.Close()
Return Nothing
End Function
Private Sub ListView_ColumnClick(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles ListViewActeurs.ColumnClick
If Me.ListViewActeurs.Sorting = SortOrder.Ascending Then
Me.ListViewActeurs.Sorting = SortOrder.Descending
Else
Me.ListViewActeurs.Sorting = SortOrder.Ascending
End If
Me.ListViewActeurs.ListViewItemSorter = New ListViewItemComparer(e.Column, Me.ListViewActeurs.Sorting)
End Sub
Private Sub BtnFermer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnFermer.Click
Close()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Init_SansPhoto()
End Sub
Private Sub BtnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPrint.Click
Me.PrintDocument1.DefaultPageSettings.Margins = New Margins(50, 50, 50, 50)
Me.PrintDocument1.OriginAtMargins = True
Me.PrintPreviewDialog1.ShowDialog()
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim rec As New Rectangle(New Point(10, 10), Me.ListViewActeurs.PreferredSize)
Dim monimage As New Bitmap(rec.Width, rec.Height)
Me.ListViewActeurs.DrawToBitmap(monimage, rec)
e.Graphics.DrawImage(monimage, New Point(10, 10))
End Sub
End Class |
Partager