下面代码是用笨方法根据扩展名显示相对应图标,比较麻烦。
在论坛看到使用:Dim icon As Icon = System.Drawing.Icon.ExtractAssociatedIcon("d:\test.xls")可以直接获取对应文件名图标。
怎么把标红的代码应用到下面代码中?
Dim ftp1 As New FtpClient
ftp1.Host = FtpIp
ftp1.Account = FtpUser
ftp1.Password = FtpPass
Dim lvw As WinForm.ListView = e.Form.Controls("ListView1")
'lvw.Images.AddImage("China","China.Ico","China48.Ico")
lvw.StopRedraw()
lvw.Groups.Clear() '清除原来的分组
lvw.Columns.Clear() '清除原来的列
lvw.Rows.Clear() '清除原来的行
lvw.Images.Clear() '清除原来的图片
lvw.View = ViewMode.Details
lvw.GridLines = True '显示网格线
lvw.Images.LargeSize = new size(16,16)
Dim ics As String() = {"doc","docx","rtf","","","","","","","txt","other"} '定义扩展名数组
Dim kzms As String ="doc txt other" '定义已知扩展名的文本串
For Each ic As String In ics
lvw.Images.AddImage(ic,ic & ".ico",ic & ".ico") '向listview里添加图标
Next
'e.form.controls("listview1").backcolor = Color.Red
'e.form.controls("ListView1").basecontrol.BackColor=color.red
Dim cls() As String = {"FileName","FileSize","CreaTime"} '指定要显示的各列
Dim cls1() As String = {"文件名","文件大小","修改时间"}
Dim wds() As Integer = {400,100,150} '定义列宽
For i As Integer = 0 To cls.Length - 1 '增加列
Dim c As WinForm.ListViewColumn = lvw.Columns.Add()
c.Name = cls(i) '指定列名
c.Text = cls1(i) '指定标题,这里标题和列名相同
c.Width = wds(i) '指定列宽
Next
lvw.Columns("FileSize").TextAlign = HorizontalAlignment.Center
lvw.Columns("CreaTime").TextAlign = HorizontalAlignment.Center
lvw.Columns("FileName").TextAlign = HorizontalAlignment.Center
For Each s As String In Tables("表A").Current.DataRow.Lines("FileName")
'从数据表中提取数据
Dim Parts() As String = s.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
For Each cl As String In cls '逐列取值
Select Case cl
'Case "人口","面积" '如果是人口列或面积列
'r(cl) = format(s(cl),"#,000") '则显示千位分割符号
Case "FileName"
r(cl) = s
Case "FileSize"
r(cl) = Format(ftp1.GetFileSize(s)/1024/1024,"0.00") & "MB"
Case "CreaTime"
r(cl)=ftp1.GetFileTime(s)
End Select
Next
Next
lvw.ResumeRedraw() '恢复绘制
ftp1.Close()