将列表视图选择的项目转换为字符串 [英] converting a listview selected item to string
本文介绍了将列表视图选择的项目转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
要开始使用VB的新功能,我试图创建一个应用程序启动器,该应用程序启动器从文件夹中拉出我要启动的项目.我可以使用图标加载这些项目,唯一的问题是我正在打开列表视图框中选择的项目要字符串化,以便我可以在其余代码中使用它.
这是我到目前为止的代码,帮助会很棒.我的主要目标是做到这一点,因此当我双击某个项目时,它将打开该项目的所有内容.即vbs脚本或文本文件.
To start off im new to VB and I m trying to create an application launcher that pulls the items i want to launch from a folder.I can get the items to load with the icon, the only are im having is turning the selected item in a list view box to string so i can use it a a variable in the rest of my code.
here is the code i have so far, Help would be great. my main goal is to make it so when i double click an item it will open what ever that item is. ie a vbs script or a text file.
Imports System.IO
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Dir As New DirectoryInfo("C:\Program Files (x86)\AutoHotkey")
FillListView(Dir)
End Sub
Private Sub FillListView(ByVal Folder As DirectoryInfo)
Static ImageList As New ImageList With {.ColorDepth = ColorDepth.Depth32Bit, .ImageSize = New Size(22, 22)}
Static ImgIndex As Integer = 0
ListView1.LargeImageList = ImageList
ListView1.View = View.Tile
For Each F As FileInfo In Folder.GetFiles("*.exe")
ImageList.Images.Add(Drawing.Icon.ExtractAssociatedIcon(F.FullName))
ListView1.Items.Add(F.Name, ImgIndex).Tag = F
ImgIndex += 1
Next
For Each F As FileInfo In Folder.GetFiles("*.txt")
ImageList.Images.Add(Drawing.Icon.ExtractAssociatedIcon(F.FullName))
ListView1.Items.Add(F.Name, ImgIndex).Tag = F
ImgIndex += 1
Next
For Each F As FileInfo In Folder.GetFiles("*.hta")
ImageList.Images.Add(Drawing.Icon.ExtractAssociatedIcon(F.FullName))
ListView1.Items.Add(F.Name, ImgIndex).Tag = F
ImgIndex += 1
Next
For Each F As FileInfo In Folder.GetFiles("*.vbs")
ImageList.Images.Add(Drawing.Icon.ExtractAssociatedIcon(F.FullName))
ListView1.Items.Add(F.Name, ImgIndex).Tag = F
ImgIndex += 1
Next
For Each Dir As DirectoryInfo In Folder.GetDirectories
FillListView(Dir)
Next
End Sub
End Class
推荐答案
尝试:
try this:
fname= Listview1.SelectedItems(0).Text
这篇关于将列表视图选择的项目转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文