在listview中打开项目的文件目录 [英] Open file directory of a item in listview

查看:74
本文介绍了在listview中打开项目的文件目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!

我正在创建一个任务管理器,但我有一个问题:

i想要创建一个按钮,打开我列表视图中所选项目的目录

如果有人可以帮助我,请回答。谢谢!



 Imports System.IO 

Public Class Form1

Dim File As New Process()

Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles ListView1.SelectedIndexChanged

End Sub

Public Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles MyBase.Load
Dim P As New Process()
Dim Count As Integer = 0
ListView1 .Items.Clear()
For Each P In Process.GetProcesses(My.Computer.Name)
On Error Resume Next
ListView1.Items.Add(P.ProcessName)
ListView1.Items(Count).SubItems.Add(FormatNumber(Math.Round(P.PrivateMemorySize64 / 1024),0))
ListView1.Items(Count).SubItems.Add(P.Responding)
ListView1.Items(Count).SubItems.Add(P.StartTime.ToString.Trim)
ListView1.Items(Count).SubItems.Ad d(P.Id)
Count = Count + 1
Next
End Sub
Private Sub KillProcess()
On Error GoTo Handled
For Each P作为ListViewItem在ListView1.SelectedItems
System.Diagnostics.Process.GetProcessById(P.SubItems(4).Text).Kill()
P.SubItems.Clear()
Next
处理:
MsgBox(Echech de fermer le processus)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles Button1.Click
KillProcess()
End Sub
Private Sub GetProcess()
Dim P As New Process()
Dim Count As Integer = 0
ListView1.Items。 Clear()
For Each P In Process.GetProcesses(My.Computer.Name)
On Error Resume Next
ListView1.Items.Add(P.ProcessName)
ListView1.Items (计数).SubItems.Add(FormatNumber(Math.Round(P.PrivateMemorySize64 / 1024),0))
ListView1.Items(Count).SubItems.Add(P.Responding)
ListView1.Items(Count).SubItems.Add(P.StartTime.ToString.Trim)
ListView1.Items(Count).SubItems.Add(P.Id)
Count = Count + 1
Next
End Sub

Private Sub Button2_Click( ByVal sender As System.Object,ByVal e As System.EventArgs)Handles Button2.Click
GetProcess()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
For Each P作为ListViewItem在ListView1.SelectedItems
System.Diagnostics.Process.GetProcessById(P.SubItems(4).Text)
Directory.GetCurrentDirectory()
下一个

结束子

结束
对不起................
Button3不起作用

解决方案

在TreeView控件的MSDN示例上有类似的代码。请查看: http://msdn.microsoft.com/en -us / library / system.windows.forms.listview.selecteditems.aspx [ ^ ]



您可以创建一个类(ProcessInfo或其他东西)包含有关检索到的进程的信息,并将该类的实例存储在每个生成的TreeViewItem的Tag属性中。当用户选择一个项目时,您只需检索所选项目的标签,将它们转换为ProcessInfo并从那里检索目录。



Uros

Hello !
I am creating a task manager but i have a problem :
i want to create a button that will open the directory of a item selected in my listview
SO if anyone can help me ,please answer. Thanks!

Imports System.IO

Public Class Form1

    Dim File As New Process()

    Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged

    End Sub

    Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim P As New Process()
        Dim Count As Integer = 0
        ListView1.Items.Clear()
        For Each P In Process.GetProcesses(My.Computer.Name)
            On Error Resume Next
            ListView1.Items.Add(P.ProcessName)
            ListView1.Items(Count).SubItems.Add(FormatNumber(Math.Round(P.PrivateMemorySize64 / 1024), 0))
            ListView1.Items(Count).SubItems.Add(P.Responding)
            ListView1.Items(Count).SubItems.Add(P.StartTime.ToString.Trim)
            ListView1.Items(Count).SubItems.Add(P.Id)
            Count = Count + 1
        Next
    End Sub
    Private Sub KillProcess()
        On Error GoTo Handled
        For Each P As ListViewItem In ListView1.SelectedItems
            System.Diagnostics.Process.GetProcessById(P.SubItems(4).Text).Kill()
            P.SubItems.Clear()
        Next
Handled:
        MsgBox("Echech de fermer le processus")
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        KillProcess()
    End Sub
    Private Sub GetProcess()
        Dim P As New Process()
        Dim Count As Integer = 0
        ListView1.Items.Clear()
        For Each P In Process.GetProcesses(My.Computer.Name)
            On Error Resume Next
            ListView1.Items.Add(P.ProcessName)
            ListView1.Items(Count).SubItems.Add(FormatNumber(Math.Round(P.PrivateMemorySize64 / 1024), 0))
            ListView1.Items(Count).SubItems.Add(P.Responding)
            ListView1.Items(Count).SubItems.Add(P.StartTime.ToString.Trim)
            ListView1.Items(Count).SubItems.Add(P.Id)
            Count = Count + 1
        Next
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        GetProcess()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        For Each P As ListViewItem In ListView1.SelectedItems
            System.Diagnostics.Process.GetProcessById(P.SubItems(4).Text)
            Directory.GetCurrentDirectory()
        Next

    End Sub

End 
Sorry ................
Button3 don't work

解决方案

You have a similar code on MSDN samples for the TreeView control. Take a look at: http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.selecteditems.aspx[^]

You could create a class (ProcessInfo or something) which would contain info about the retrieved processes and store the instance of that class in the Tag property of each generated TreeViewItem. When the user selects an item, you just retrieve the tag of the selected item(s), cast them to ProcessInfo and retrive the directory from there.

Uros


这篇关于在listview中打开项目的文件目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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