-
March 8th, 2001, 08:23 PM
#1
Listview to listview copy
I'm looking for some sample code that shows you how to copy selected contents from one listview control to another listview control. Can anyone help me out with that?
Thanks much.
-
March 9th, 2001, 10:51 AM
#2
Re: Listview to listview copy
Put two listboxes and a command button on a form.
Paste this code into the General Declarations section of the form.
Make List1.MultiSelect = 1 or 2
Run the program. Select more than one from List1, then click the button.
option Explicit
private Sub Command1_Click()
Dim X
for X = 0 to List1.ListCount - 1
If List1.Selected(X) = true then
List2.AddItem List1.List(X)
End If
next X
End Sub
private Sub Form_Load()
Dim X
for X = 0 to 25
List1.AddItem "Item " & X
next X
End Sub
John G
-
March 9th, 2001, 03:13 PM
#3
Re: Listview to listview copy
Create a new form add two listviews on the form
and then paste this code in
private Sub Form_Load()
'This routine assumes you want to add items from the same list
With ListView1
.View = lvwReport
.ColumnHeaders.Add , "Junk", "Junk" 'add some headers
.ColumnHeaders.Add , "Junk1", "Sub Junk"
.ColumnHeaders.Add , "Junk2", "Sub Junk"
.OLEDragMode = ccOLEDragAutomatic
.ListItems.Add 1, "MyNode" & 1, "MyNode1" 'add somedata
.ListItems(1).SubItems(1) = "MyJunk5"
.ListItems(1).SubItems(2) = "MsdsyJunk5"
.ListItems.Add 2, "MyNode" & 2, "MyNode2"
.ListItems(2).SubItems(1) = "MyJunk3"
.ListItems(1).SubItems(2) = "MyJusddnk5"
End With
With ListView2
.ColumnHeaders.Add , "Junk", "Junk"
.ColumnHeaders.Add , "Junk1", "Sub Junk"
.ColumnHeaders.Add , "Junk2", "Sub Junk"
.View = lvwReport
.OLEDragMode = ccOLEDragAutomatic
End With
End Sub
private Sub ListView2_OLEDragDrop(Data as MSComctlLib.DataObject, Effect as Long, Button as Integer, Shift as Integer, x as Single, y as Single)
Dim iSubCnt as Integer 'Holds the subItems
Dim OList as ListItem
set iList = ListView1.SelectedItem 'Copy from the first list view
iSubCnt = ListView1.ColumnHeaders.Count - 1 '-1 for the listitem
set OList = ListView2.ListItems.Add(, iList.Key, iList.Text)
With ListView1.SelectedItem
If iSubCnt >= 1 then 'then we have subitems
for intLoop = 0 to iSubCnt - 1
OList.SubItems(intLoop + 1) = .SubItems(intLoop + 1)
next
End If
End With
ListView1.ListItems.Remove ListView1.SelectedItem.Key
End Sub
Yahoo Messenger ID dfWade10900
-
March 13th, 2001, 04:17 PM
#4
Re: Listview to listview copy
Thank you for your replies -- much appreciated.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|