想将listview1的数据拖放到listview2中。
ListView2_OLEDragDrop这个方法该如何写?
Data.GetData(vbCFText)这样可以得到listview1.SelectedItem.Text的值,能否得到listview1.SelectedItem..SubItems(i)的值呢?
ListView2_OLEDragDrop这个方法该如何写?
Data.GetData(vbCFText)这样可以得到listview1.SelectedItem.Text的值,能否得到listview1.SelectedItem..SubItems(i)的值呢?
Private Sub TV_OLEDragDrop(Data As MSComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)
Listview2.ListItems.Add ,,listview1.selecteditem.text 'listview2增加一行,文本是listview1拖入的item的文本
ListView1.ListItems.Remove Listview1.SelectedItem.Index 'listview删除拖出的item
End Sub
注:listview1的拖动模式设置为1,listview2的放置模式设置为1
Option Explicit
Private Sub Form_Load()
TreeView1.Nodes.Add , , "aa", "aa"
TreeView1.Nodes.Add , , "bb", "bb"
ListView1.ListItems.Add , , "cc"
ListView1.ListItems.Add , , "dd"
ListView1.OLEDragMode = ccOLEDragAutomatic
ListView1.LabelEdit = lvwManual
End Sub
Private Sub ListView1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then
ListView1.DragIcon = ListView1.SelectedItem.CreateDragImage
ListView1.Drag vbBeginDrag
End If
End Sub
Private Sub TreeView1_DragDrop(Source As Control, x As Single, y As Single)
If Not TreeView1.DropHighlight Is Nothing Then
TreeView1.Nodes.Add TreeView1.DropHighlight.Key, tvwChild, GetNextKey() & ListView1.SelectedItem.Text, ListView1.SelectedItem.Text
TreeView1.DropHighlight.Expanded = True
End If
End Sub
Private Sub TreeView1_DragOver(Source As Control, x As Single, y As Single, State As Integer)
Set TreeView1.DropHighlight = TreeView1.HitTest(x, y)
End Sub
Private Function GetNextKey() As String
Dim sNewKey As String
Dim iHold As Integer
Dim i As Integer
On Error GoTo myerr
iHold = Val(TreeView1.Nodes(1).Key)
For i = 1 To TreeView1.Nodes.Count
If Val(TreeView1.Nodes(i).Key) > iHold Then
iHold = Val(TreeView1.Nodes(i).Key)
End If
Next
iHold = iHold + 1
sNewKey = CStr(iHold) & "_"
GetNextKey = sNewKey
Exit Function
myerr:
GetNextKey = "1_"
End Function
最后我就是这样实现的,绕过OLE了。@ lxcc(虫子|专注于抢分)
抢分也注意别人的问题啊,OLE,您的粘的好像不是吧?