本文介绍了如何在Listviwe Control Vb.Net中仅显示没有完整路径的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将文件添加到我的listviwe控件而不显示完整路径感谢



我的代码是

如果我尝试要添加更多文件到我的列表视图,它将复制

i will like to add file to my listviwe control without the full path showing thanks

my code is
and if i try to add more file to my listview it will duplicate

Imports System.IO
Imports System.Text

Public Class Form1
    Dim objItem As ListViewItem
    Private playList As New ArrayList

    Public Sub SaveArrayList(ByVal path As String, ByVal arrayList As ArrayList)

        Try
            Dim writer As New StreamWriter(path, False, Encoding.Unicode)

            For Each s As String In arrayList
                writer.WriteLine(s.ToString)
            Next

            writer.Close()
        Catch ex As Exception
            Debug.Write(ex.ToString)
        End Try

    End Sub
    Public Function LoadArrayList(ByVal path As String) As ArrayList

        Try
            If Not File.Exists(path) Then
                Return New ArrayList
            End If

            Dim reader As New StreamReader(path, True), s As String, list As New ArrayList

            Do
                s = reader.ReadLine
                If s = vbNullString Then Exit Do 'you can use the .Peek method aswell...
                list.Add(s)
            Loop 'Until reader.Peek = -1

            reader.Close()

            Return list

        Catch ex As Exception
            Debug.Write(ex.ToString)
            Return New ArrayList
        End Try

    End Function

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If OpenFileDialog1.ShowDialog(Me) = DialogResult.OK Then
            playList.AddRange(OpenFileDialog1.FileNames)
            SaveArrayList("C:\playlist.txt", playList)
            For Each File In playList
                ' objItem.myplaylist.Items.Add(File)
                objItem = myplaylist.Items.Add(File)
                objItem.SubItems.Add((New FileInfo(File).Length / 1000).ToString("f2") + " " + "KB")
            Next
        End If
    End Sub
End Class



请帮助我可以渲染我的gr8full


pls i need any help u can render am gr8full

推荐答案

Dim playList As New ArrayList
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.Multiselect = true
Dim dr As DialogResult = OpenFileDialog1.ShowDialog()
If (dr = System.Windows.Forms.DialogResult.OK) Then
        playList.AddRange((From x in OpenFileDialog1.FileNames select Path.GetFileName(x)).ToArray())
        playList.Dump()
End If


If OpenFileDialog1.ShowDialog(Me) = DialogResult.OK Then
           playList.Clear()
           playList.AddRange(OpenFileDialog1.FileNames)
           'SaveArrayList("C:\playlist.txt", playList)
           For Each File In playList
               '        ' objItem.myplaylist.Items.Add(File)
               objItem = myplaylist.Items.Add(My.Computer.FileSystem.GetFileInfo(File).Name)
               '        objItem = myplaylist.Items.Add(File)
               objItem.SubItems.Add((New FileInfo(File).Length / 1000).ToString("f2") + " " + "KB")
           Next
       End If


这篇关于如何在Listviwe Control Vb.Net中仅显示没有完整路径的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 22:39