如何使用列表视图复选框选择文件夹 [英] How to use the listview checkbox to select a folder

查看:113
本文介绍了如何使用列表视图复选框选择文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用带有复选框的listview选项来复制文件夹。例如,我在c:\ test\jobfolder \ job1和c:\ test \ jobobder \ job2等文件夹中有一个文件夹。在列表视图框中我可以用复选框列出这些文件夹但是我是什么无法弄清楚是如何编程事件来获取job1文件夹作为变量所以我可以用它来复制到另一个位置。



我想要将本地c:\ test\jobfolder \ job1复制到网络位置。所以我可以使用以下代码复制文件夹,但我需要定义字符串值。



Dim sourceDirectory As String = System.IO.Path.Combine( C:\ test\jobs,(strjobno))

Dim destinationDirectory As String = System.IO.Path.Combine(f:\\\\completed,(strjobno))



我可以在其他地方使用此代码,我可以将作业号定义为strjobno。



好​​像我错过了一些简单的东西。我可以使用列表框工作,然后单击作业编号,但我想使用listview / checkbox选项,这样我就可以选择多个作业文件夹并执行for / next循环将每个作业文件夹复制到另一个位置。



对于列表框,我使用的代码工作正常。

Dim strjobno As String = ListBox1.SelectedItem.ToString()



感谢您的帮助!

I am trying to use the listview option with checkboxes to copy a folder. So for example, I have a folder on c:\test\jobfolder\job1 and c:\test\jobfolder\job2, etc. In the listview box I can list these folders with the checkboxes but what I can't figure out is how to program the event to pick up the job1 folder as a variable so I can use it to copy to another location.

I want to copy the local c:\test\jobfolder\job1 to a network location. So I can use the following code to copy the folder but I need to define the string value.

Dim sourceDirectory As String = System.IO.Path.Combine("C:\test\jobs", (strjobno))
Dim destinationDirectory As String = System.IO.Path.Combine("f:\test\completed", (strjobno))

I can use this code in other places where I can define the job number as strjobno.

It seems like I am missing something simple. I can make it work with a listbox and I click on the job number, but I would like to use the listview/checkbox option so I can select multiple job folders and do a for/next loop to copy each job folder to another location.

For the listbox I am using this code that is working fine.
Dim strjobno As String = ListBox1.SelectedItem.ToString()

Thanks for your help!

推荐答案

我通过使用checkedlistbox选项来解决这个问题



关键是使用itemchecked变量tostring()



见下面的代码....希望这个可以帮助别人。谢谢



Dim itemChecked As Object

For Each itemChecked In CheckedListBox1.CheckedItems



Dim sourceDirectory As String = System.IO.Path.Combine(C:\files\jobs,itemChecked.ToString())

Dim destinationDirectory As String = System.IO.Path .Combine(\\server\Documents\folder,itemChecked.ToString())







如果是System.IO.Directory.Exists(destinationDirectory)那么







FileIO .FileSystem.CopyDirectory(sourceDirectory,destinationDirectory,

FileIO.UIOption.AllDialogs)





System.IO .Directory.Delete(sourceDirectory,True)







否则

MsgBox(找不到工作号码......+ itemChec ked.ToString()+请联系派遣创建工号,然后再试,_

vbExclamation,_

找不到工作)

GoTo afterloop

结束如果





下一页



MsgBox(工作顺利完成,_

vbInformation,_

工作完成)

afterloop:



'用当前工作重新填充我的列表框



CheckedListBox1.Items.Clear()

Dim dir As DirectoryInfo

dir = New DirectoryInfo(C:\ job)

For Each subdir As DirectoryInfo in dir.GetDirectories

CheckedListBox1.Items.Add(subdir.Name)

下一页

'结束检查当前工作
I figured this out by using a checkedlistbox option

The key was to use the itemchecked variable "tostring()"

See code below....hope this may help someone else. Thanks

Dim itemChecked As Object
For Each itemChecked In CheckedListBox1.CheckedItems

Dim sourceDirectory As String = System.IO.Path.Combine("C:\files\jobs", itemChecked.ToString())
Dim destinationDirectory As String = System.IO.Path.Combine("\\server\Documents\folder", itemChecked.ToString())



If System.IO.Directory.Exists(destinationDirectory) Then



FileIO.FileSystem.CopyDirectory(sourceDirectory, destinationDirectory,
FileIO.UIOption.AllDialogs)


System.IO.Directory.Delete(sourceDirectory, True)



Else
MsgBox("Job Number not found.... " + itemChecked.ToString() + " Please contact dispatch to create job number and then try again", _
vbExclamation, _
"Job Not Found")
GoTo afterloop
End If


Next

MsgBox("Job Completed Successfully", _
vbInformation, _
"Job Complete")
afterloop:

're-populate my listbox with current jobs

CheckedListBox1.Items.Clear()
Dim dir As DirectoryInfo
dir = New DirectoryInfo("C:\jobs")
For Each subdir As DirectoryInfo In dir.GetDirectories
CheckedListBox1.Items.Add(subdir.Name)
Next
'end checking for current jobs


这篇关于如何使用列表视图复选框选择文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆