-- 作者:wwwzhucom
-- 发布时间:2013/8/17 11:55:00
-- treeview控件和临时表的使用
大家好,我想建一个窗体,窗体左边用treeview控件,右边用一个临时表,通过选择或单击左边的节点,右边临时表中显示筛选的结果(根据节点名称筛选),出现了一个问题,就是要先选择左边的节点,再打开该窗体,右边临时表才会显示筛选的内容,怎样先单击左边的节点后,右边的临时表的内容就变化啊,不需要重负的打开窗口,谢谢了
NodeMouseClick的事件代码如下:
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1") trv.BuildTree("充电柜信息","编号") Dim dtb As New DataTableBuilder("初始化表") dtb.AddDef("充电位号", Gettype(Integer), 150) dtb.AddDef("姓名", Gettype(String), 150) dtb.AddDef("部门", Gettype(String),150) dtb.AddDef("IC卡号", Gettype(String),150) dtb.Build() Tables("初始化窗口_Table1").datasource= Tables("初始化表") Dim str As String ="" Dim k As Integer=Val(e.node.name) Vars("Num")=k Dim tb As Table tb=Tables("人员信息") tb.applyfilter=False tb.Filter="[充电位]>=" & k * 100+1 & " And [充电位]<= " & k * 100+96 & " " If tb.Rows.count>0 Then tb.sort="充电位" For i As Integer=0 To tb.rows.count-1 tb.Position=i Dim dr1 As Row = Tables("初始化表").AddNew() dr1("充电位号")=tb.current("充电位") dr1("姓名")=tb.current("姓名") dr1("部门")=tb.current("部门") dr1("IC卡号")=tb.current("IC卡编号") Next Else Dim t2 As Table t2 = Tables("初始化表") If t2.Rows.count>0 Then For i As Integer = 0 To t2.Rows.Count-1 t2.position=i t2.Current.delete() Next End If End If
窗口加载事件(AfterLoad事件)的代码如下:
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1") trv.BuildTree("充电柜信息","编号") Dim t1 As Table t1=Tables("充电柜信息") Dim t2 As Table t2=Tables("人员信息") Dim dtb As new DataTableBuilder("初始化表") dtb.AddDef("充电位号",Gettype(Integer),150) dtb.AddDef("姓名",Gettype(String),150) dtb.AddDef("部门",Gettype(String),150) dtb.AddDef("IC卡号",Gettype(String),150) dtb.Build() Tables("初始化窗口_Table1").datasource= Tables("初始化表") Dim m As Integer=Vars("Num") If m>0 Then t2.ApplyFilter=False t2.filter="[充电位] >= " & m * 100 +1 & " and [充电位] <= " & m * 100 +96 If t2.Rows.count>0 Then t2.Sort="充电位" For j As Integer=0 To t2.Rows.count-1 t2.position=j Dim dr As Row=Tables("初始化表").AddNew() dr("充电位号")=t2.current("充电位") dr("姓名")=t2.current("姓名") dr("部门")=t2.current("部门") dr("IC卡号")=t2.current("IC卡编号") Next Tables("初始化窗口_Table1").datasource= Tables("初始化表") End If Else For i As Integer=0 To t1.Rows.count-1 t1.position=i Dim str As String=t1.current("编号") Dim k As Integer=Val(str) t2.ApplyFilter=False t2.filter="[充电位] >= " & k * 100 +1 & " and [充电位] <= " & k * 100 +96 If t2.Rows.count>0 Then t2.sort="充电位" For j As Integer=0 To t2.Rows.count-1 t2.position=j Dim dr As Row=Tables("初始化表").AddNew() dr("充电位号")=t2.current("充电位") dr("姓名")=t2.current("姓名") dr("部门")=t2.current("部门") dr("IC卡号")=t2.current("IC卡编号") Next Tables("初始化窗口_Table1").datasource= Tables("初始化表") Exit For End If Next End If
|