I found this code from a link that someone put on this website. I don't remember exactly where it is, and I apoligize to the person that made this code for not giving you recognition. But I assume since it was posted on here, you don't mind that it was public. So now that you have your answer, do you know a good way to print items in a ListView?
VB Code:
Private Sub MoveListViewItem (ByRef lv as ListView, ByVal MoveUp as Boolean)
Dim I As Integer
Dim cache As String
Dim selIdx As Integer
With lv
selIdx = .SelectedItems.Item(0).Index
If MoveUp Then
'ignore moveup of row(0)
If selIdx = 0 Then
Exit Sub
End If
'move the subitems for the previous row
'to cache so we can move the selected row up
For i = 0 To .Items(SelIdx).SubItems.Count - 1
cache = .Items(selIdx - 1).SubItems(i).Text
.Items(selIdx - 1).SubItems(i).Text = .Items selIdx).SubItems(i).Text
.Items(selIdx).SubItems(i).Text = cache
Next
.Items(selIdx - 1).Selected = True
.Refresh()
.Focus()
Else
'ignore move down of last row
If selIdx = .Items.Count - 1 Then
Exit Sub
End If
'move the subitems for the next row
'to cache so we can move the selectedrow down
For i = 0 To .Items(SelIdx).SubItems.Count - 1
cache = .Items(selIdx + 1).SubItems(i).Text
.Items(selIdx + 1).SubItems(i).Text = .Items selIdx).SubItems(i).Text
.Items(selIdx).SubItems(i).Text = cache
Next
.Items(selIdx + 1).Selected = True
.Refresh()
.Focus()
End If
Now Code the MoveUp and MoveDown buttons to do the appropriate actions.
For the MoveUp:
VB Code:
If ListView.SelectedIndicies.Count = 0 Then Exit Sub
MoveListViewItem(ListView, MoveUp:=True)
And the MoveDown:
VB Code:
If ListView.SelectedIndicies.Count = 0 Then Exit Sub
MoveListViewItem(ListView, MoveUp:=False)