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
| Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports ListviewSubitemsIcones.OAKListView
Public Class Form1
Private listView1 As OAKListView = New OAKListView
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
CreateMyListView()
End Sub
Private Sub CreateMyListView()
' Create a new ListView control.
'Dim listView1 As New OAKListView
listView1.Bounds = New Rectangle(New Point(10, 10), New Size(424, 200))
' Set the view to show details.
listView1.View = Windows.Forms.View.Details
' Allow the user to edit item text.
listView1.LabelEdit = True
' Allow the user to rearrange columns.
listView1.AllowColumnReorder = True
' Display check boxes.
listView1.CheckBoxes = True
' Select the item and subitems when selection is made.
listView1.FullRowSelect = True
' Create three items and three sets of subitems for each item.
Dim item1 As New ListViewItem("item1", imageIndex:=0)
' Place a check mark next to the item.
'item1.Checked = True
item1.SubItems.Add("1")
'addImagSubItem() '(0, 1, "Paste", 1)
item1.SubItems.Add("2")
'addImagSubItem() '(1, 2, "2", 2)
item1.SubItems.Add("3")
'addImagSubItem() '(0, 3, "3", 3)
Dim item2 As New ListViewItem("item2", 1)
item2.SubItems.Add("4")
item2.SubItems.Add("5")
item2.SubItems.Add("6")
Dim item3 As New ListViewItem("item3", 2)
' Place a check mark next to the item.
'item3.Checked = True
item3.SubItems.Add("7")
item3.SubItems.Add("8")
item3.SubItems.Add("9")
' Create columns for the items and subitems.
listView1.Columns.Add("Item Column", 100, HorizontalAlignment.Left)
listView1.Columns.Add("Column 2", 80, HorizontalAlignment.Left)
listView1.Columns.Add("Column 3", 120, HorizontalAlignment.Left)
listView1.Columns.Add("Column 4", 120, HorizontalAlignment.Center)
'Add the items to the ListView.
listView1.Items.AddRange(New ListViewItem() {item1, item2, item3})
'Assign the ImageList objects to the ListView.
listView1.SmallImageList = ImageList1
' Add the ListView to the control collection.
Me.Controls.Add(listView1)
'Après avoir créé le contrôle on ajoute image et texte aux subItems.
addImagSubItem(0, 1, "Paste", 1)
addImagSubItem(0, 2, "Cut", 0)
End Sub 'CreateMyListView
Private Sub addImagSubItem(ByVal row As Integer, ByVal col As Integer, ByVal text As String, ByVal numImageList As Integer)
Dim lvi As New OAKListView.LV_ITEM()
' Row
lvi.iItem = row
' Column
lvi.iSubItem = col
lvi.pszText = text
lvi.mask = OAKListView.LVIF_IMAGE Or OAKListView.LVIF_TEXT
' Image index on imagelist
lvi.iImage = numImageList
OAKListView.SendMessage(listView1.Handle, OAKListView.LVM_SETITEM, 0, lvi)
End Sub
End Class |
Partager