以文本方式查看主题 - 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=189363) |
-- 作者:lianghanyu -- 发布时间:2023/11/28 8:35:00 -- ListView遍历出错 以下代码,在遍历第二个For时,会报错提示: \'================================================================================生成表格 Dim ins() As String = {"产品2D", "产品3D", "物性表", "DFM反馈", "产品反馈", "EGP反馈", "OKTT反馈", "模流反馈", "3D反馈", "热嘴反馈", "信息汇总"} Dim outs() As String = {"组立图", "修改后产品", "推荐材料", "发出DFM", "产品问题", "发出EGP", "发出OKTT", "模流分析", "3D设计", "热嘴报价", "其它的"} Dim lvw As WinForm.ListView = Forms("信息总表").Controls("file") 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.GridLines = True \'显示网格线 lvw.View = ViewMode.Details \'显示模式为详细信息 lvw.Images.LargeSize = New size(32, 32) Dim cls() As String = {"接收文件", "修改日期1", "发出文件", "修改日期2"} \'定义列名 Dim wds() As Integer = {100, 200, 100, 200} \'定义列宽 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 For k As Integer = 0 To ins.Length - 1 \'增加行,这里增加的是接收的行 Dim r As WinForm.ListViewRow = lvw.Rows.Add() If k Mod 2 = 0 Then \'除2为偶数 \'设置交替行背景颜色 r.BackColor = Color.DarkSeaGreen End If r("接收文件") = ins(k) r("发出文件") = outs(k) Next For Each vr As WinForm.ListViewRow In lvw.Rows Dim tx As String = vr.Cells("发出文件").Text MessageBox.Show(tx) Next \'第二个fot语句就会报错?????????????? For Each cr As WinForm.ListViewRow In lvw.Rows MessageBox.Show(cr.Cells("接收文件").Text) Next lvw.ResumeRedraw() \'恢复绘制
|
-- 作者:有点蓝 -- 发布时间:2023/11/28 8:40:00 -- 第一个列要这样访问 For Each cr As WinForm.ListViewRow In lvw.Rows MessageBox.Show(cr.Text) Next |