Dim lvw As WinForm.ListView = Forms("住宿状态").Controls("ListViewindex")
lvw.StopRedraw() '暂停绘制
lvw.Rows.Clear() '清除原来的行
lvw.Images.Clear() '清除原来的图片
lvw.View = ViewMode.LargeIcon '显示模式为大图标
lvw.Images.AddLargeImage("kong", "kong.png") '
lvw.Images.AddLargeImage("man", "man.png") '
lvw.Images.AddLargeImage("yu", "yu.png") '
lvw.Images.AddLargeImage("cuo", "cuo.png") '
lvw.Images.LargeSize = New Size(120,60) '定义大图标尺寸
For Each dr As DataRow In DataTables("宿舍基础数据").DataRows '从数据表中提取数据
Dim vr As WinForm.ListViewRow = lvw.Rows.Add() '增加一行
vr.Text = dr("楼号") & dr("宿舍") & vbcrlf & "可住" & dr("可住人数") & "人" & "已住" & dr("已住人数") &"人" & "空" & dr("空余床位") '设置标题
If dr("状态") = "空宿舍" Then '设置分组
vr.ImageKey = "kong"
ElseIf dr("状态") = "已住满" Then '设置分组
vr.ImageKey = "man"
ElseIf dr("状态") = "有余床" Then '设置分组
vr.ImageKey = "yu"
ElseIf dr("状态") = "出错了" Then '设置分组
vr.ImageKey = "cuo"
End If
vr.Tag= dr '将DataRow赋值给ListViewRow的Tag属性,将二者联系起来
Next
lvw.ResumeRedraw() '恢复绘制-
----------------RowActivate
Dim lvw As WinForm.ListView = e.Form.Controls("ListViewindex")
Dim vr As WinForm.ListViewRow = lvw.Current '获取ListView的当前行
If vr Is Nothing Then '如果不存在当前行,也就是内有选定任何一行
Return
End If
If vr.ImageKey = "kong" Or vr.ImageKey = "man" Or vr.ImageKey = "yu" Or vr.ImageKey = "cuo" Then
Dim btn As WinForm.Button = e.Form.Controls("Button1")
btn.PerformClick() '点击任何一个,打开对应的
End If
此主题相关图片如下:360截图20200703073707154.jpg
想要单击对应的宿舍图标,下面的“住宿生信息”表中只显示对应的楼号和宿舍的人员信息,自己弄了半天没有做出来
[此贴子已经被作者于2020/7/3 7:47:18编辑过]