Click here to Skip to main content
15,886,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When i copy the selected item(s) of listview file type then paste to desktop so 1 only can paste but the selected is 3 items. how to loop or array the item to be multiple copy.

What I have tried:

For Each lvi As ListViewItem In ListView1.SelectedItems
                   For Each info2 In New DirectoryInfo(Me.dirPath).GetFiles(Conversions.ToString(Operators.ConcatenateObject(Operators.ConcatenateObject("*", lvi.Text), "*")), SearchOption.AllDirectories)
                       Dim data As New DataObject()
                       If File.Exists(info2.FullName) Then
                           Try
                               Dim DataObject As New DataObject
                               Dim tempFileArray As New ArrayList
                               tempFileArray.Add(Path.GetFullPath(info2.FullName))
                               DataObject.SetData(DataFormats.FileDrop, False, DirectCast(tempFileArray.ToArray(GetType(String)), String()))
                               Clipboard.SetDataObject(DataObject)

                               'Dim data As New System.Collections.Specialized.StringCollection()
                               'data.Add(info2.FullName)
                               'Clipboard.SetFileDropList(data)
                           Catch exception1 As Exception
                               Dim ex As Exception = exception1
                               ProjectData.SetProjectError(ex)
                               Interaction.MsgBox(ex.Message, MsgBoxStyle.ApplicationModal, Nothing)
                               ProjectData.ClearProjectError()
                           End Try
                       End If
                   Next
               Next
Posted
Updated 8-Mar-20 17:29pm

1 solution

First, this line is complete garbage:
or Each info2 In New DirectoryInfo(Me.dirPath).GetFiles(Conversions.ToString(Operators.ConcatenateObject(Operators.ConcatenateObject("*", lvi.Text), "*")), SearchOption.AllDirectories)

Break that line into individual statements so you can debug what's going on in it. Do not bury method/property calls inside other method/property calls. All you're doing is making your code more complete and making it harder to debug, as in this case.

On top of that, you're hiding all kinds of functionality in crap classes like "Operators" so it's impossible for anyone to tell you exactly what's going on and how to fix it.

At a glance, I can see at least 5+ new methods you should be creating to handle individual tasks, like returning a list of files from a given path. I can also recommend you get rid of the "Operators" class, or whatever it is.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900