vb.net 如何打开listbox被选中文件夹

listbox中有好几个文件,同时显示文件所在的路径,例如e:\zbzh\2001\test.txt,我现在想选中一个文件,点击一个按钮,就自动打开该文件的文件夹,怎么做... listbox中有好几个文件,同时显示文件所在的路径,例如e:\zbzh\2001\test.txt,我现在想选中一个文件,点击一个按钮,就自动打开该文件的文件夹,怎么做? 展开
 我来答
haokeyy
2010-04-19 · TA获得超过1487个赞
知道小有建树答主
回答量:1002
采纳率:0%
帮助的人:1126万
展开全部
'在窗体启动时,给列表初始化,测试用,随便添加了几条列表项,并将列表的扩展多选功能打开。
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListBox1.Items.Add("c:\windows\notepad.exe")
ListBox1.Items.Add("c:\windows\system32\notepad.exe")
ListBox1.Items.Add("C:\WINDOWS\Web\Wallpaper\Bliss.bmp")
ListBox1.Items.Add("c:\windows\system32\drivers")
ListBox1.Items.Add("c:\dddddd")
ListBox1.Items.Add("c:\dos\2\3.txt")
ListBox1.SelectionMode = SelectionMode.MultiExtended
End Sub

'打开列表中所有选中的文件或者文件夹,并判断是否存在。
'如果是文件夹直接打开,如果是文件,打开目录后,并自动选中该文件
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim pr As Process = New Process
Dim curFile As String
For i = 0 To ListBox1.SelectedItems.Count - 1
pr.StartInfo.FileName = "explorer.exe"
curFile = ListBox1.SelectedItems(i)
If System.IO.Directory.Exists(curFile) Then
pr.StartInfo.Arguments = Chr(34) & curFile & Chr(34)
Else
If System.IO.File.Exists(curFile) Then
pr.StartInfo.Arguments = "/n,/select," & Chr(34) & ListBox1.SelectedItems(i) & Chr(34)
Else
Continue For
End If
End If
pr.Start()
Next
pr = Nothing
End Sub
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
换号多次
2010-04-19 · TA获得超过560个赞
知道小有建树答主
回答量:931
采纳率:0%
帮助的人:628万
展开全部
Dim a As Integer
Dim b As Integer
Dim c As String
MsgBox(ListBox1.SelectedItem.ToString)
1:
Shell("cmd /c start c:\")
a = InStr(a + 1, ListBox1.SelectedItem.ToString, "\")
If a <> 0 Then b = a : GoTo 1
c = ListBox1.SelectedItem.ToString
Shell("cmd /c start " & Microsoft.VisualBasic.Left(c, b))
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式