简体   繁体   English

如何在 VB.Net 的 ListView 中显示图标

[英]How to display icon in ListView in VB.Net

Can you help me to display icon view from the files i get from a directory你能帮我从目录中获得的文件中显示图标视图吗

Here is my code.这是我的代码。

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SearchDir("g:\")
    End Sub

    Public Sub SearchDir(ByVal sDir As String)
        Dim fil As String

        Try
            For Each dir As String In Directory.GetDirectories(sDir)
                For Each fil In Directory.GetFiles(dir, " *.doc ")
                    ListView1.Items.Add(fil)
                Next
                SearchDir(dir)
            Next

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class

this gives me a result, but in form of string displaying its path这给了我一个结果,但是以字符串的形式显示它的路径

First of all, you need to add ImageList tool from Visual Studio Toolbox.首先,您需要从 Visual Studio Toolbox 添加ImageList工具。 Then select its properties and select the images you need to work with.然后 select 它的属性和 select 你需要使用的图像。

图像列表工具 ImageList 的配置

After that, you need to use the corresponding given serial-wise IDs by ImageList in your ListView code as follows:之后,您需要在ListView代码中使用ImageList对应的给定串行 ID,如下所示:

Declaration:宣言:

Private lView As ListViewItem ' listView's lView (not I-view)

lView = ListView1.Items.Add("Special iconic thing", 0) ' 0 = my icon ID in ImageList

You should get the similar to my output:你应该得到类似于我的 output:

结果

Hope it works for you.希望对你有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM