Hi Florian,
das geht so - ist aber ein wenig komplex
Option Explicit
<font color=green>' UDT - Benutzerdefinierte Datentypen
' zum Speichern eines ListView-Items</font>
Private Type UDT_SubItem
Bold As Boolean
ForeColor As Long
Key As String
ReportIcon As Long
Tag As Variant
Text As String
ToolTipText As String
End Type
Private Type UDT_ListItem
Bold As Boolean
Checked As Boolean
ForeColor As Long
Ghosted As Boolean
Icon As Long
Key As String
Selected As Boolean
SmallIcon As Long
Tag As Variant
Text As String
ToolTipText As String
SubItems() As UDT_SubItem
End Type <font color=green>' Zwei ListView-Items miteinander vertauschen</font>
Private Sub lvwSwap(itemX As ListItem, itemY As ListItem)
Dim UDT_ItemX As UDT_ListItem
Dim UDT_ItemY As UDT_ListItem
Dim sKey As String
<font color=green>' List-Items in UDT-Datentyp speichern</font>
UDT_ItemX = lvwItem_To_UDT(itemX)
UDT_ItemY = lvwItem_To_UDT(itemY)
<font color=green>' Achtung! Key-Wert muss temporär geändert, da es
' sonst zum Fehler "Doppelter schlüssel in Auflistung"
' kommen kann</font>
sKey = UDT_ItemY.Key: UDT_ItemY.Key = "~temp"
<font color=green>' ItemX und ItemY vertauschen</font>
lvwUDT_To_Item itemX, UDT_ItemY
lvwUDT_To_Item itemY, UDT_ItemX
<font color=green>' Key-Werte wiederherstellen</font>
itemX.Key = sKey
End Sub <font color=green>' Kopie eines LisView-Items erstellen</font>
Private Function lvwItem_To_UDT(oItem As ListItem) _
As UDT_ListItem
Dim i As Integer
With lvwItem_To_UDT
<font color=green>' Eigenschaften</font>
.Bold = oItem.Bold
.Checked = oItem.Checked
.ForeColor = oItem.ForeColor
.Ghosted = oItem.Ghosted
.Icon = oItem.Icon
.Key = oItem.Key
.Selected = oItem.Selected
.SmallIcon = oItem.SmallIcon
.Tag = oItem.Tag
.Text = oItem.Text
.ToolTipText = oItem.ToolTipText
<font color=green>' SubItems</font>
ReDim .SubItems(oItem.ListSubItems.Count)
For i = 1 To oItem.ListSubItems.Count
With .SubItems(i)
.Bold = oItem.ListSubItems(i).Bold
.ForeColor = oItem.ListSubItems(i).ForeColor
.Key = oItem.ListSubItems(i).Key
.ReportIcon = oItem.ListSubItems(i).ReportIcon
.Tag = oItem.ListSubItems(i).Tag
.Text = oItem.ListSubItems(i).Text
.ToolTipText = oItem.ListSubItems(i).ToolTipText
End With
Next i
End With
End Function <font color=green>' UDT-Datentyp nach Item</font>
Private Sub lvwUDT_To_Item(oItem As ListItem, _
UDT_Item As UDT_ListItem)
Dim i As Integer
With UDT_Item
<font color=green>' Eigenschaften</font>
oItem.Bold = .Bold
oItem.Checked = .Checked
oItem.ForeColor = .ForeColor
oItem.Ghosted = .Ghosted
oItem.Icon = .Icon
oItem.Key = .Key
oItem.Selected = .Selected
oItem.SmallIcon = .SmallIcon
oItem.Tag = .Tag
oItem.Text = .Text
oItem.ToolTipText = .ToolTipText
<font color=green>' SubItems</font>
For i = 1 To oItem.ListSubItems.Count
With .SubItems(i)
oItem.ListSubItems(i).Bold = .Bold
oItem.ListSubItems(i).ForeColor = .ForeColor
oItem.ListSubItems(i).Key = .Key
oItem.ListSubItems(i).ReportIcon = .ReportIcon
oItem.ListSubItems(i).Tag = .Tag
oItem.ListSubItems(i).Text = .Text
oItem.ListSubItems(i).ToolTipText = .ToolTipText
End With
Next i
End With
End Sub Und hier der Aufruf zum Verschieben der Einträge
<font color=green>' nach unten verschieben</font>
Private Sub lvw_MoveDown()
Dim oItem_x As ListItem
Dim oItem_y As ListItem
Dim Index As Integer
With ListView1
If Not .SelectedItem Is Nothing Then
Index = .SelectedItem.Index
If Index < .ListItems.Count Then
Set oItem_x = .ListItems(Index)
Set oItem_y = .ListItems(Index + 1)
lvwSwap oItem_x, oItem_y
End If
End If
End With
End Sub <font color=green>' nach oben verschieben</font>
Private Sub lvw_MoveUp()
Dim oItem_x As ListItem
Dim oItem_y As ListItem
Dim Index As Integer
With ListView1
If Not .SelectedItem Is Nothing Then
Index = .SelectedItem.Index
If Index > 1 Then
Set oItem_x = .ListItems(Index)
Set oItem_y = .ListItems(Index - 1)
lvwSwap oItem_x, oItem_y
End If
End If
End With
End Sub Cu
Dieter |