以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- ListView显示文件问题 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=178768) |
-- 作者:lianghanyu -- 发布时间:2022/7/19 19:49:00 -- ListView显示文件问题 如下代码: Dim path As String = "\\标准库\\冷却系列\\HASCO" Dim lvw As WinForm.ListView = Forms("客户标准").controls("ListView1") Dim ha As Integer = lvw.Position lvw.Font = New Font("宋体", 12)\'设置字体型号与大小 lvw.StopRedraw() \'停止绘制 lvw.Groups.Clear() \'清除原来的分组 lvw.Columns.Clear() \'清除原来的列 lvw.Rows.Clear() \'清除原来的行 lvw.Images.Clear() \'清除原来的图片 lvw.View = ViewMode.Details \'显示模式为详细信息 lvw.Images.LargeSize = New size(32, 32) Dim ics As String() = {"swf", "accdb", "mdb", "psd", "png", "xls", "xlsx", "bmp", "rar", "jpg", "doc", "docx", "zip", "pdf", "txt", "ppt", "pptx", "exe", "other", "dwg", "prt", "SLDPRT", "dxf", "eml", "stp", "step", "igs", "x_t"} \'定义扩展名数组 Dim kzms As String = "swf accdb mdb psd png xls xlsx bmp rar jpg doc docx zip pdf txt ppt pptx exe dwg prt SLDPRT dxf eml stp step igs x_t" \'定义已知扩展名的文本串 For Each ic As String In ics lvw.Images.AddImage(ic, ic & ".png", ic & ".png") \'向listview里添加图标 Next Dim cls() As String = {"序号", "文件名称", "图档上传日期", "大小"} \'定义列名 Dim wds() As Integer = {50, 350, 180, 150} \'定义列宽 For i As Integer = 0 To cls.Length - 1 \'增加列 Dim c As WinForm.ListViewColumn = lvw.Columns.Add() c.Name = cls(i) \'指定列名 c.Text = cls(i) \'指定标题,这里标题和列名相同 c.Width = wds(i) \'指定列宽 Next Dim dls As List(Of String) dls = ftp.GetDetailList(path) If dls.Count < = 0 Then Dim r As WinForm.ListViewRow = lvw.Rows.Add() \'增加一行 r("文件名称") = "暂时没有文件" Else Dim dics As New SortedDictionary(Of String, String) For Each dl As String In dls Dim Parts() As String = dl.Split("*") dics.Add(Parts(1) & dl, dl) Next Dim arr(dics.keys.count - 1) As String dics.keys.copyto(arr, 0) For i As Integer = arr.length - 1 To 0 Step - 1 Dim dl As String = dics(arr(i)) Dim Parts() As String = dl.Split("*") Dim r As WinForm.ListViewRow = lvw.Rows.Add() \'增加一行 Dim Dot As Integer = parts(0).LastIndexOf(".") \'定义.的位置 Dim kzm As String = parts(0).SubString(Dot + 1) \'获取扩展名 \' If kzms.Contains(kzm) = True Then \'若为已知扩展名 r.ImageKey = kzm \'指定行的图标键值 Else r.ImageKey = "other" End If r("序号") = i + 1 r("文件名称") = Parts(0) MessageBox.Show(Parts(0)) r("图档上传日期") = Parts(1) If parts(2) > 1024 Then r("大小") = format(parts(2) / 1048576, "0.0") & "MB" Else r("大小") = Parts(2) & "B" End If Next |
-- 作者:有点蓝 -- 发布时间:2022/7/19 20:23:00 -- 自行调试 Dim dics As New SortedDictionary(Of String, String) For Each dl As String In dls msgbox(dl) Dim Parts() As String = dl.Split("*") msgbox(Parts(1)) dics.Add(Parts(1) & dl, dl) Next Dim arr(dics.keys.count - 1) As String dics.keys.copyto(arr, 0) For i As Integer = arr.length - 1 To 0 Step - 1 msgbox(“i=” & i) Dim dl As String = dics(arr(i)) msgbox(“dl=” & dl) Dim Parts() As String = dl.Split("*") msgbox(“parts(0)=” & parts(0)) Dim r As WinForm.ListViewRow = lvw.Rows.Add() \'增加一行 Dim Dot As Integer = parts(0).LastIndexOf(".") \'定义.的位置 Dim kzm As String = parts(0).SubString(Dot + 1) \'获取扩展名 msgbox(“kzm=” & kzm) If kzms.Contains(kzm) = True Then \'若为已知扩展名 r.ImageKey = kzm \'指定行的图标键值 Else r.ImageKey = "other" End If r("序号") = i + 1 r("文件名称") = Parts(0) |