Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
'These are the object declarations used... besides a counter later, this is all that's needed
Dim lvItem As ListViewItem
Dim myGrp As ListViewGroup
'This prevents flickering as items are added and moved on the list view.
ListView1.BeginUpdate()
'Make sure no col headers are shown
ListView1.HeaderStyle = ColumnHeaderStyle.None
'And view in LArge Icon mode
ListView1.View = View.LargeIcon
'Either of those last two commands can be adjusted to your liking
'Here I create the first list view item
_User = User.NewUser("Tech", "Gnome", "")
lvItem = New ListViewItem(_User.ToStringArray, -1)
lvItem.Tag = _User
ListView1.Items.Add(lvItem) 'And add it to the list view
'Now create a group
myGrp = New ListViewGroup("WelcomeUser", "Welcome!")
ListView1.Groups.Add(myGrp) 'Add the group....
ListView1.Groups(myGrp.Name).Items.Add(lvItem) 'And add my item to the group
'New item... same object !
lvItem = New ListViewItem("Current Sales", -1)
lvItem.Tag = Nothing
ListView1.Items.Add(lvItem)
'New group... again, recycling the previous group object
myGrp = New ListViewGroup("TodayStatus", "Where You Are Today...")
ListView1.Groups.Add(myGrp)
ListView1.Groups(myGrp.Name).Items.Add(lvItem)
'Here I create and add multiple listviewitems to the group I just created
myGrp = New ListViewGroup("Today", "Today")
ListView1.Groups.Add(myGrp)
lvItem = New ListViewItem("Print Jobs", 0)
lvItem.Tag = Nothing
ListView1.Items.Add(lvItem)
ListView1.Groups(myGrp.Name).Items.Add(lvItem)
lvItem = New ListViewItem("Appointments", 0)
lvItem.Tag = Nothing
ListView1.Items.Add(lvItem)
ListView1.Groups(myGrp.Name).Items.Add(lvItem)
lvItem = New ListViewItem("Calls", 0)
lvItem.Tag = Nothing
ListView1.Items.Add(lvItem)
ListView1.Groups(myGrp.Name).Items.Add(lvItem)
lvItem = New ListViewItem("Tasks", 0)
lvItem.Tag = Nothing
ListView1.Items.Add(lvItem)
ListView1.Groups(myGrp.Name).Items.Add(lvItem)
'At this point, I loop through all of the existing items that are in my list view (created in another button click event)
'And based on the LastName property of the class stored in the .Tag property...
For Each lvitm As ListViewItem In ListView1.Items
If TypeOf lvitm.Tag Is Customer Then
'Create a group...
myGrp = New ListViewGroup(CType(lvitm.Tag, Customer).LastName, CType(lvitm.Tag, Customer).LastName)
'If that group already exists in the ListView...
If ListView1.Groups.Contains(myGrp) Then
'Add the lsit view item to the EXISTING group (using the name)
ListView1.Groups(myGrp.Name).Items.Add(lvitm)
Else
'If it does not exist, add the group
ListView1.Groups.Add(myGrp)
'And add the item to the group
ListView1.Groups(myGrp.Name).Items.Add(lvitm)
End If
End If
Next
'Allow the control up update itself.
ListView1.EndUpdate()
End Sub