Dim Filter As String = ""
If e.Node.Name <> "加载所有行" Then '要用Name属性,不能用Text属性
Dim lb1 As String = e.Node.DataRow("人员类别")
Dim zt As String = e.Node.DataRow("人员状态")
Select Case e.Node.Level
Case 0
Filter = "人员类别 = '" & lb1 & "'"
Dim lvw As WinForm.ListView
lvw = e.Form.CreateControl("ListView1", ControlTypeEnum.ListView)'设置控件ListView的名称及类型
lvw.StopRedraw() '停止绘制
lvw.Groups.Clear() '清除原来的分组
lvw.Columns.Clear() '清除原来的列
lvw.Rows.Clear() '清除原来的行
lvw.Images.Clear() '清除原来的图片
lvw.Dock = System.Windows.Forms.DockStyle.Fill'设置停靠位置
lvw.View = ViewMode.Details '显示模式为详细信息
lvw.TitleSize = New Size(130, 80) '设置平铺区域大小
lvw.GridLines = True '显示网格线
lvw.AllowDrag = True '允许拖动行
lvw.Images.AddImage("Man", "Man.ico", "Man48.ico") '添加代表男性的一对图标,图标键值为“Man”
lvw.Images.AddImage("Woman", "Woman.ico", "Woman48.ico") '添加代表女性的一对图标,图标键值为“Woman”
e.Form.Controls("SplitContainer1").Panel2.AddControl(lvw)'创建控件ListView
Dim cls() As String = {"姓名", "人员类别", "进入单位日期", "离开单位日期", "人员状态"} '定义列名
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.TextAlign = HorizontalAlignment.Center
Next
For Each lb As String In DataTables("EI").GetValues("人员类别") '增加分组
Dim grp As WinForm.ListViewGroup = lvw.Groups.Add()
grp.Name = lb
grp.Text = lb
Next
For Each dr As DataRow In DataTables("EI").DataRows
Dim r As WinForm.ListViewRow = lvw.Rows.Add() '增加一行
r.Group = dr("人员类别") '指定所属分组
For Each cl As String In cls '逐列取值
r(cl) = dr(cl)
Next
If dr("性别") = "男" Then '设置分组
r.ImageKey = "Man"
Else
r.ImageKey = "Woman"
End If
r.Tag = dr'将DataRow赋值给ListViewRow的Tag属性,将二者联系起来
Next
For Each c As WinForm.ListViewColumn In lvw.Columns
c.AutoResize
Next
lvw.ShowGroups = False
lvw.ResumeRedraw() '恢复绘制
Case 1
Filter = "人员类别 ='" & lb1 & "' And 人员状态 = '" & zt & "'"
Case 2
End Select
End If
DataTables("EI").LoadFilter = Filter
DataTables("EI").Load()
效果是有了,但是感觉不伦不类啊,即使我把代码放在了单击事件,但是每次单击先是表格变化,Listview不变,再单击ListView才会变,是不是我实现的方式方法不对。其次,点击加载所有行,表格变化了,ListView不会变化要怎么解决?
[此贴子已经被作者于2023/12/14 17:34:53编辑过]