Option Strict On Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub Private components As System.ComponentModel.IContainer 'Required by the Windows Form Designer '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. Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox Friend WithEvents rdTop As System.Windows.Forms.RadioButton Friend WithEvents rdLeft As System.Windows.Forms.RadioButton Friend WithEvents rdDefault As System.Windows.Forms.RadioButton Friend WithEvents ListView1 As System.Windows.Forms.ListView Friend WithEvents ColumnHeaderCompany As System.Windows.Forms.ColumnHeader Friend WithEvents ColumnHeaderContact As System.Windows.Forms.ColumnHeader Friend WithEvents ColumnHeaderTel As System.Windows.Forms.ColumnHeader Friend WithEvents ColumnHeaderFAX As System.Windows.Forms.ColumnHeader Friend WithEvents bttnEnumerate As System.Windows.Forms.Button Friend WithEvents bttnPopulate As System.Windows.Forms.Button Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox Friend WithEvents rdDetails As System.Windows.Forms.RadioButton Friend WithEvents rdList As System.Windows.Forms.RadioButton Friend WithEvents rdSmallIcons As System.Windows.Forms.RadioButton Friend WithEvents rdIcons As System.Windows.Forms.RadioButton Friend WithEvents bttnIterate As System.Windows.Forms.Button Friend WithEvents ImageList1 As System.Windows.Forms.ImageList Private Sub InitializeComponent() Me.components = New System.ComponentModel.Container() Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1)) Me.GroupBox2 = New System.Windows.Forms.GroupBox() Me.rdTop = New System.Windows.Forms.RadioButton() Me.rdLeft = New System.Windows.Forms.RadioButton() Me.rdDefault = New System.Windows.Forms.RadioButton() Me.ListView1 = New System.Windows.Forms.ListView() Me.ColumnHeaderCompany = New System.Windows.Forms.ColumnHeader() Me.ColumnHeaderContact = New System.Windows.Forms.ColumnHeader() Me.ColumnHeaderTel = New System.Windows.Forms.ColumnHeader() Me.ColumnHeaderFAX = New System.Windows.Forms.ColumnHeader() Me.bttnEnumerate = New System.Windows.Forms.Button() Me.bttnPopulate = New System.Windows.Forms.Button() Me.GroupBox1 = New System.Windows.Forms.GroupBox() Me.rdDetails = New System.Windows.Forms.RadioButton() Me.rdList = New System.Windows.Forms.RadioButton() Me.rdSmallIcons = New System.Windows.Forms.RadioButton() Me.rdIcons = New System.Windows.Forms.RadioButton() Me.bttnIterate = New System.Windows.Forms.Button() Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components) Me.GroupBox2.SuspendLayout() Me.GroupBox1.SuspendLayout() Me.SuspendLayout() ' 'GroupBox2 ' Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.rdTop, Me.rdLeft, Me.rdDefault}) Me.GroupBox2.Font = New System.Drawing.Font("Tahoma", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.GroupBox2.Location = New System.Drawing.Point(431, 158) Me.GroupBox2.Name = "GroupBox2" Me.GroupBox2.Size = New System.Drawing.Size(128, 112) Me.GroupBox2.TabIndex = 6 Me.GroupBox2.TabStop = False Me.GroupBox2.Text = "Icon Placement" ' 'rdTop ' Me.rdTop.Font = New System.Drawing.Font("Tahoma", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.rdTop.Location = New System.Drawing.Point(16, 88) Me.rdTop.Name = "rdTop" Me.rdTop.Size = New System.Drawing.Size(80, 16) Me.rdTop.TabIndex = 2 Me.rdTop.Text = "Top" ' 'rdLeft ' Me.rdLeft.Font = New System.Drawing.Font("Tahoma", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.rdLeft.Location = New System.Drawing.Point(16, 60) Me.rdLeft.Name = "rdLeft" Me.rdLeft.Size = New System.Drawing.Size(80, 16) Me.rdLeft.TabIndex = 1 Me.rdLeft.Text = "Left" ' 'rdDefault ' Me.rdDefault.Checked = True Me.rdDefault.Font = New System.Drawing.Font("Tahoma", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.rdDefault.Location = New System.Drawing.Point(16, 32) Me.rdDefault.Name = "rdDefault" Me.rdDefault.Size = New System.Drawing.Size(80, 16) Me.rdDefault.TabIndex = 0 Me.rdDefault.TabStop = True Me.rdDefault.Text = "Default" ' 'ListView1 ' Me.ListView1.AllowColumnReorder = True Me.ListView1.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeaderCompany, Me.ColumnHeaderContact, Me.ColumnHeaderTel, Me.ColumnHeaderFAX}) Me.ListView1.GridLines = True Me.ListView1.HideSelection = False Me.ListView1.LargeImageList = Me.ImageList1 Me.ListView1.Location = New System.Drawing.Point(7, 6) Me.ListView1.Name = "ListView1" Me.ListView1.Size = New System.Drawing.Size(416, 384) Me.ListView1.SmallImageList = Me.ImageList1 Me.ListView1.Sorting = System.Windows.Forms.SortOrder.Ascending Me.ListView1.TabIndex = 4 ' 'ColumnHeaderCompany ' Me.ColumnHeaderCompany.Text = "Company" Me.ColumnHeaderCompany.Width = 120 ' 'ColumnHeaderContact ' Me.ColumnHeaderContact.Text = "Contact" Me.ColumnHeaderContact.Width = 100 ' 'ColumnHeaderTel ' Me.ColumnHeaderTel.Text = "Telephone" ' 'ColumnHeaderFAX ' Me.ColumnHeaderFAX.Text = "FAX" ' 'bttnEnumerate ' Me.bttnEnumerate.Font = New System.Drawing.Font("Tahoma", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.bttnEnumerate.Location = New System.Drawing.Point(431, 318) Me.bttnEnumerate.Name = "bttnEnumerate" Me.bttnEnumerate.Size = New System.Drawing.Size(128, 32) Me.bttnEnumerate.TabIndex = 8 Me.bttnEnumerate.Text = "Enumerate List" ' 'bttnPopulate ' Me.bttnPopulate.Font = New System.Drawing.Font("Tahoma", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.bttnPopulate.Location = New System.Drawing.Point(431, 278) Me.bttnPopulate.Name = "bttnPopulate" Me.bttnPopulate.Size = New System.Drawing.Size(128, 32) Me.bttnPopulate.TabIndex = 9 Me.bttnPopulate.Text = "Populate List" ' 'GroupBox1 ' Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.rdDetails, Me.rdList, Me.rdSmallIcons, Me.rdIcons}) Me.GroupBox1.Font = New System.Drawing.Font("Tahoma", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.GroupBox1.Location = New System.Drawing.Point(431, 6) Me.GroupBox1.Name = "GroupBox1" Me.GroupBox1.Size = New System.Drawing.Size(128, 144) Me.GroupBox1.TabIndex = 5 Me.GroupBox1.TabStop = False Me.GroupBox1.Text = "List Style" ' 'rdDetails ' Me.rdDetails.Font = New System.Drawing.Font("Tahoma", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.rdDetails.Location = New System.Drawing.Point(16, 111) Me.rdDetails.Name = "rdDetails" Me.rdDetails.Size = New System.Drawing.Size(96, 24) Me.rdDetails.TabIndex = 3 Me.rdDetails.Text = "Details" ' 'rdList ' Me.rdList.Font = New System.Drawing.Font("Tahoma", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.rdList.Location = New System.Drawing.Point(16, 82) Me.rdList.Name = "rdList" Me.rdList.Size = New System.Drawing.Size(96, 24) Me.rdList.TabIndex = 2 Me.rdList.Text = "List" ' 'rdSmallIcons ' Me.rdSmallIcons.Font = New System.Drawing.Font("Tahoma", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.rdSmallIcons.Location = New System.Drawing.Point(16, 53) Me.rdSmallIcons.Name = "rdSmallIcons" Me.rdSmallIcons.Size = New System.Drawing.Size(96, 24) Me.rdSmallIcons.TabIndex = 1 Me.rdSmallIcons.Text = "Small Icons" ' 'rdIcons ' Me.rdIcons.Checked = True Me.rdIcons.Font = New System.Drawing.Font("Tahoma", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.rdIcons.Location = New System.Drawing.Point(16, 24) Me.rdIcons.Name = "rdIcons" Me.rdIcons.Size = New System.Drawing.Size(96, 24) Me.rdIcons.TabIndex = 0 Me.rdIcons.TabStop = True Me.rdIcons.Text = "Icons" ' 'bttnIterate ' Me.bttnIterate.Font = New System.Drawing.Font("Tahoma", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte)) Me.bttnIterate.Location = New System.Drawing.Point(431, 358) Me.bttnIterate.Name = "bttnIterate" Me.bttnIterate.Size = New System.Drawing.Size(128, 32) Me.bttnIterate.TabIndex = 7 Me.bttnIterate.Text = "Selected Items" ' 'ImageList1 ' Me.ImageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16) Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer) Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(566, 397) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.bttnEnumerate, Me.bttnPopulate, Me.GroupBox1, Me.bttnIterate, Me.GroupBox2, Me.ListView1}) Me.Name = "Form1" Me.Text = "ListView Demo" Me.GroupBox2.ResumeLayout(False) Me.GroupBox1.ResumeLayout(False) Me.ResumeLayout(False) End Sub #End Region ' This project doesn't have a Load and Save command. ' You can copy all of the list's Items to an ArrayList and ' persist it to a text file. Just create a Structure with a field ' for each SubItem, store each item to an instance of the custom Structure ' and then add all these variables to an ArrayList Private Sub rdDetails_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdDetails.CheckedChanged ListView1.View = View.Details End Sub Private Sub rdList_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdList.CheckedChanged ListView1.View = View.List End Sub Private Sub rdSmallIcons_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdSmallIcons.CheckedChanged ListView1.View = View.SmallIcon End Sub Private Sub rdIcons_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdIcons.CheckedChanged ListView1.View = View.LargeIcon End Sub Private Sub rdDefault_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdDefault.CheckedChanged ListView1.ArrangeIcons(ListViewAlignment.Default) End Sub Private Sub rdLeft_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdLeft.CheckedChanged ListView1.ArrangeIcons(ListViewAlignment.Left) End Sub Private Sub rdTop_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdTop.CheckedChanged ListView1.ArrangeIcons(ListViewAlignment.Top) End Sub Private Sub bttnEnumerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnEnumerate.Click Dim i, j As Integer Dim LItem As ListViewItem For i = 0 To ListView1.Items.Count - 1 LItem = ListView1.Items(i) Console.WriteLine(LItem.Text) For j = 0 To LItem.SubItems.Count - 1 Console.WriteLine(" " & ListView1.Columns(j).Text & " " & LItem.SubItems(j).Text) Next Next End Sub Private Sub ListView1_ColumnClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles ListView1.ColumnClick Select Case e.Column Case 0 ListView1.ListViewItemSorter = New ListCompanySorter() ListView1.Sort() Case 1 ListView1.ListViewItemSorter = New ListContactSorter() ListView1.Sort() End Select End Sub Private Sub ListView1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.Click Dim LItem As ListViewItem Dim LItems As ListView.SelectedListViewItemCollection LItems = ListView1.SelectedItems For Each LItem In LItems Console.Write(LItem.Text & vbTab) Console.Write(LItem.SubItems(0).ToString & vbTab) Console.Write(LItem.SubItems(1).ToString & vbTab) Console.WriteLine(LItem.SubItems(2).ToString & vbTab) Next End Sub Private Sub bttnIterate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnIterate.Click Dim LItem As ListViewItem Dim I As Integer For Each LItem In ListView1.SelectedItems For I = 0 To LItem.SubItems.Count - 1 Console.Write(LItem.SubItems(I).Text & vbTab) Next Console.Write(vbCrLf) Next End Sub Private Sub bttnPopulate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnPopulate.Click Dim LItem As New ListViewItem() LItem.Text = "Alfreds Futterkiste" LItem.SubItems.Add("Anders Maria") LItem.SubItems.Add("030-0074321") LItem.SubItems.Add("030-0076545") LItem.ImageIndex = 0 ListView1.Items.Add(LItem) LItem = New ListViewItem() LItem.Text = "Around the Horn" LItem.SubItems.Add("Hardy Thomas") LItem.SubItems.Add("(171) 555-7788") LItem.SubItems.Add("(171) 555-6750") LItem.ImageIndex = 0 ListView1.Items.Add(LItem) LItem = New ListViewItem() LItem.Text = "Princesa Isabel Vinhos" LItem.SubItems.Add("de Castro Isabel") LItem.SubItems.Add("(1) 356-5634") LItem.SubItems.Add("") LItem.ImageIndex = 0 ListView1.Items.Add(LItem) LItem = New ListViewItem() LItem.Text = "Furia Bacalhau e Frutos do Mar" LItem.SubItems.Add("Rodriguez Lino") LItem.SubItems.Add("(1) 354-2534") LItem.SubItems.Add("(1) 354-2535") LItem.ImageIndex = 0 ListView1.Items.Add(LItem) LItem = New ListViewItem() LItem.Text = "Alfreds Futterkiste" LItem.SubItems.Add("Anders Maria") LItem.SubItems.Add("030-0074321") LItem.SubItems.Add("030-0076545") LItem.ImageIndex = 0 ListView1.Items.Add(LItem) LItem = New ListViewItem() LItem.Text = "Around the Horn" LItem.SubItems.Add("Hardy Thomas") LItem.SubItems.Add("(171) 555-7788") LItem.SubItems.Add("(171) 555-6750") LItem.ImageIndex = 0 ListView1.Items.Add(LItem) LItem = New ListViewItem() LItem.Text = "Bottom-Dollar Markets" LItem.SubItems.Add("Lincoln Elizabeth") LItem.SubItems.Add("(604) 555-4729") LItem.SubItems.Add("(604) 555-3745") LItem.ImageIndex = 0 ListView1.Items.Add(LItem) LItem = New ListViewItem() LItem.Text = "Cactus Comidas para llevar" LItem.SubItems.Add("SimpsonPatricio") LItem.SubItems.Add("(1)135-5555") LItem.SubItems.Add("(1)135-4892") LItem.ImageIndex = 0 ListView1.Items.Add(LItem) LItem = New ListViewItem() LItem.Text = "Eastern Connection" LItem.SubItems.Add("Devon Ann") LItem.SubItems.Add("(171) 555-0297") LItem.SubItems.Add("(171) 555-3373") LItem.ImageIndex = 0 ListView1.Items.Add(LItem) LItem = New ListViewItem() LItem.Text = "Galería del gastrónomo" LItem.SubItems.Add("Saavedra Eduardo") LItem.SubItems.Add("(93) 203 4560") LItem.SubItems.Add("(93) 203 4561") LItem.ImageIndex = 0 ListView1.Items.Add(LItem) LItem = New ListViewItem() LItem.Text = "Godos Cocina Típica" LItem.SubItems.Add("Freyre José Pedro") LItem.SubItems.Add("(95) 555 82 82") LItem.SubItems.Add("(93) 203 4561") LItem.ImageIndex = 0 ListView1.Items.Add(LItem) LItem = New ListViewItem() LItem.Text = "Island Trading" LItem.SubItems.Add("Bennett Helen") LItem.SubItems.Add("(198) 555-8888") LItem.SubItems.Add("(93) 203 4561") LItem.ImageIndex = 0 ListView1.Items.Add(LItem) LItem = New ListViewItem() LItem.Text = "La maison d'Asie" LItem.SubItems.Add("Roulet Annette") LItem.SubItems.Add("61.77.61.10") LItem.SubItems.Add("61.77.61.11") LItem.ImageIndex = 0 ListView1.Items.Add(LItem) LItem = New ListViewItem() LItem.Text = "Rattlesnake Canyon Grocery" LItem.SubItems.Add("Wilson Paula") LItem.SubItems.Add("(505) 555-5939") LItem.SubItems.Add("(505) 555-3620") LItem.ImageIndex = 0 ListView1.Items.Add(LItem) LItem = New ListViewItem() LItem.Text = "The Big Cheese" LItem.SubItems.Add("Nixon Liz") LItem.SubItems.Add("(503) 555-3612") LItem.SubItems.Add("") LItem.ImageIndex = 0 ListView1.Items.Add(LItem) LItem = New ListViewItem() LItem.Text = "Victuailles en stock" LItem.SubItems.Add("SaveleyMary") LItem.SubItems.Add("78.32.54.86") LItem.SubItems.Add("78.32.54.87") LItem.ImageIndex = 0 ListView1.Items.Add(LItem) LItem = New ListViewItem() LItem.Text = "Wartian Herkku" LItem.SubItems.Add("Koskitalo Pirkko") LItem.SubItems.Add("981-443655") LItem.SubItems.Add("981-443655") LItem.ImageIndex = 0 ListView1.Items.Add(LItem) LItem = New ListViewItem() LItem.Text = "Wellington Importadora" LItem.SubItems.Add("Parente Paula") LItem.SubItems.Add("(14) 555-8122") LItem.SubItems.Add("") LItem.ImageIndex = 0 ListView1.Items.Add(LItem) End Sub End Class ' The ListCompanySorter contains the CompareTo method, which enables ' the control to sort its item by company name ' The Company field is the ListItem's Text property Class ListCompanySorter Implements IComparer Public Function CompareTo(ByVal o1 As Object, ByVal o2 As Object) As Integer Implements System.Collections.IComparer.Compare Dim item1, item2 As ListViewItem item1 = CType(o1, ListViewItem) item2 = CType(o2, ListViewItem) If item1.ToString.ToUpper > item2.ToString.ToUpper Then Return 1 Else If item1.ToString.ToUpper < item2.ToString.ToUpper Then Return -1 Else Return 0 End If End If End Function End Class ' The ListCompanySorter contains the CompareTo method, which enables ' the control to sort its item by contact name ' The ContactName field is the first subitem of each ListItem Class ListContactSorter Implements IComparer Public Function CompareTo(ByVal o1 As Object, ByVal o2 As Object) As Integer Implements System.Collections.IComparer.Compare Dim item1, item2 As ListViewItem item1 = CType(o1, ListViewItem) item2 = CType(o2, ListViewItem) If item1.SubItems(1).ToString.ToUpper > item2.SubItems(1).ToString.ToUpper Then Return 1 Else If item1.SubItems(1).ToString.ToUpper < item2.SubItems(1).ToString.ToUpper Then Return -1 Else Return 0 End If End If End Function End Class