PowerBuilder生成一棵实时的目录树

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/ClearLoveQ/article/details/81775206

一棵完整的树

1.首先在一个自定义函数(wf_initwindow)中设置根节点


    //====================================================================
	// 事件: 窗体名字.wf_initwindow()
	//--------------------------------------------------------------------
	// 描述:
	//--------------------------------------------------------------------
	// 参数:
	// 	value	integer	
	//--------------------------------------------------------------------
	// 返回:  (none)
	 //====================================================================
	tv_list.deleteitem(0)             //tv_list是树视图控件

	long ll_treeroothandle
	TreeViewItem ltv_node
	ltv_node.PictureIndex = 1
	ltv_node.SelectedPictureIndex = 1

	//设置树视图根节点
	if gb_chs then                     //gb_chs是语言设置
		ltv_node.Label = "公司部门"
	else
		ltv_node.Label = "Department"
	end if

	ltv_node.data = '0'               //将parent_code  作为节点的data
	ltv_node.children = true       
	ll_treeroothandle = tv_list.InsertItemLast(0, ltv_node)     //根节点的句柄是0
	//生成树
	wf_inittree('0',ll_treeroothandle)     //调用第二层自定义函数 wf_inittree,将parent_code和节点作为参数
	//展开根目录
	tv_list.expandITEM( 1)
	tv_list.selectitem(1)

2.自定义组织目录树的函数wf_inittree


    //====================================================================
	// 事件: w_maindepartment.wf_inittree()
	//--------------------------------------------------------------------
	// 描述:
	//--------------------------------------------------------------------
	// 参数:
	// 	value	string 	vs_parentid	
	// 	value	integer	vi_handle  	
	//====================================================================

	DataStore lds_dept
	TreeViewItem ltv_item
	string ls_sql,ls_void
	long ll_i,ll_root

	lds_dept= create DataStore
	lds_dept.DataObject = "ds_dept"
	lds_dept.settransobject(sqlca)
	ls_sql=lds_dept.getsqlselect( )+"  where B_Department.Parent_Code='"+vs_parentid+"' and  B_Department.DB_Name='"+gs_dbname+"'"     
	lds_dept.setsqlselect(ls_sql)
	lds_dept.retrieve( )

	string ls_deptname,ls_deptcode,ls_parentid,ls_isend
	long ll_nodehandle,ll_levelid
	for ll_i=1 to lds_dept.rowcount( )
		ls_deptcode=lds_dept.object.Dept_Code[ll_i]
		ls_deptname=lds_dept.object.Dept_Name[ll_i]
		ls_parentid=lds_dept.object.Parent_Code[ll_i]
		ls_isend=lds_dept.object.Is_End[ll_i]
		ll_levelid=lds_dept.object.level_id[ll_i]
		ls_void=lds_dept.object.status[ll_i]
		
		if ls_void='O' then        //数据苦衷要有相应的字段来判断节点的选中状态和是否是最后一层
			ltv_item.PictureIndex = 1
			ltv_item.SelectedPictureIndex = 2
		else
			ltv_item.PictureIndex = 4
			ltv_item.SelectedPictureIndex = 5
		end if
		
		if lds_dept.rowcount( )<=0 then
			exit
		end if
		
		ltv_item.Label = "["+ls_deptcode+"]  "+ls_deptname
		ltv_item.data=ls_deptcode
		
		if ls_isend='Y' then
			ltv_item.children=false
		else
			ltv_item.children=true
		end if

		ll_nodehandle=tv_list.InsertItemLast(vi_handle, ltv_item)
	end for
	destroy lds_dept
	

3.添加一个wf_cleartree函数来清除节点,否则会添加重复

//====================================================================
// 事件: w_maindepartment.wf_cleartree()
//--------------------------------------------------------------------
// 描述: 清除指定节点下的所有子节点
//--------------------------------------------------------------------
// 参数:
// 	value	integer 	ai_parenthandle	
// 	value	treeview	vtv_data       	
//--------------------------------------------------------------------
// 返回:  (none)
//--------------------------------------------------------------------
// 作者:	MONO		日期: 2009年09月26日
//--------------------------------------------------------------------
//	Copyright (c) 2002-2006 HYLANC, All rights reserved.
//--------------------------------------------------------------------
// 修改历史:
//
//====================================================================


long ll_re
ll_re = 1
do while(true)
	ll_re = vtv_data.finditem(childtreeitem!,ai_parenthandle)
	if ll_re = -1 then exit
	vtv_data.deleteitem(ll_re)
loop

4.在TreeView控件的itemexpanding事件中 调用    就可以每次点击都是实时的数据了

	
    treeviewitem treeparent
	string ls_data

	this.setredraw(false)

	//清除原有节点
	wf_cleartree(handle,this)

	//获取点击节点
	this.getitem(handle,treeparent)
	ls_data=string(treeparent.data)
	this.selectitem(handle)

	wf_inittree(ls_data,handle)

	this.setredraw( true)

​

5.数据库中的字段设置

必须要有:dept_code,parent_code,

可有可无:is_end(判断是否是最后一层),status(判断选中的状态)

展开阅读全文

javascript array生成 目录树

01-21

我在数据库得到这么一个数组,想要通过生成三层目录树,用javascript怎么组织啊?rn数据库返回信息rn[code=javascript]["child_id":[3,4,17,2],"id":1,"name":"全部","child_id":[],"id":3,"name":"内置","child_id":[11],"id":4,"name":"其他商品","child_id":[],"id":11,"name":"原材料","child_id":[],"id":17,"name":"Pet Toys","child_id":[8,9,5,7,6,10],"id":2,"name":"可销售","child_id":[],"id":8,"name":"配件","child_id":[],"id":9,"name":"组件","child_id":[],"id":5,"name":"电脑","child_id":[],"id":7,"name":"外置设备","child_id":[],"id":6,"name":"服务","child_id":[],"id":10,"name":"软件","child_id":[16,15,13,14],"id":12,"name":"苹果产品","child_id":[],"id":16,"name":"苹果配件","child_id":[],"id":15,"name":"iMac电脑","child_id":[],"id":13,"name":"iPad","child_id":[],"id":14,"name":"iPod"][/code]rnrn最终需要的数据rn[code=javascript]["child_id":["child_id":[],"id":3,"name":"内置","child_id":["child_id":[],"id":11,"name":"原材料"],"id":4,"name":"其他商品","child_id":[],"id":17,"name":"Pet Toys","child_id":["child_id":[],"id":8,"name":"配件","child_id":[],"id":9,"name":"组件","child_id":[],"id":5,"name":"电脑","child_id":[],"id":7,"name":"外置设备","child_id":[],"id":6,"name":"服务","child_id":[],"id":10,"name":"软件"],"id":2,"name":"可销售"],"id":1,"name":"全部","child_id":["child_id":[],"id":16,"name":"苹果配件","child_id":[],"id":15,"name":"iMac电脑","child_id":[],"id":13,"name":"iPad","child_id":[],"id":14,"name":"iPod"],"id":12,"name":"苹果产品"][/code] 论坛

c#中生成目录树 treeview

10-21

表结构如下:mytable rnrn_________________________________________________________________________ rn OrgID/单位ID OrgName/单位名称 UpperOrgID/上级单位ID rn A001 省教育厅 0 -----表示是顶级单位 rn A002 XX大学 A001 rn A003 XX大学理学院 A002 rn A004 YY大学 A001 rnrn_________________________________________________________________________rnrnrn想实现的TreeView如下:rnrn-省教育厅 rn -XX大学 rn --XX大学理学院 rn -YY大学 rn --XX大学理学院 rnrn----------------------------------------rn代码如下,小弟运行后,树目录不显示。请问为什么?rn谢谢rn---------------------------------------rnrnrnprivate void CreateTree()rn rnrn string str = "Data Source=ECE-6D6D44DE2AD;Initial Catalog=Kqdb;Integrated Security=True";//数据库连接rn SqlConnection conn = new SqlConnection(str);rn conn.Open();rnrn SqlCommand sqlcom = new SqlCommand("Select * from mytable where UpperOrgID='0'", conn);rn tryrn rn conn.Open();rn SqlDataReader sqlreader = sqlcom.ExecuteReader();rn while (sqlreader.Read())rn rn TreeNode mynode = new TreeNode();rn mynode.Text = sqlreader.GetString(2);rn mynode.Tag = sqlreader.GetValue(1).ToString() + '|' + sqlreader.GetValue(2).ToString() + '|' + sqlreader.GetValue(3).ToString() + '|' + sqlreader.GetValue(0).ToString();rn treeView1.Nodes.Add(mynode);rnrn NextTree(sqlreader.GetValue(0).ToString(), treeView1.Nodes[0]);rn rn rn catch (Exception ex)rn rn MessageBox.Show(ex.ToString());rn rn finallyrn rn conn.Close();rn rn rnrn private void NextTree(string nodeid, TreeNode parentnode)rn rn string str = "Data Source=ECE-6D6D44DE2AD;Initial Catalog=Kqdb;Integrated Security=True";//数据库连接rn SqlConnection conn = new SqlConnection(str);rn rnrn SqlCommand sqlcom = new SqlCommand("Select * from mytable where UpperOrgID='" + nodeid + "'",conn);rn tryrn rn conn.Open();rn SqlDataReader sqlreader = sqlcom.ExecuteReader();rnrn while (sqlreader.Read())rn rn TreeNode mynode = new TreeNode(sqlreader.GetString(2));rn parentnode.Nodes.Add(mynode);rn mynode.Tag = sqlreader.GetValue(1).ToString() + '|' + sqlreader.GetValue(2).ToString() + '|' + sqlreader.GetValue(3).ToString() + '|' + sqlreader.GetValue(0).ToString();rn NextTree(sqlreader.GetValue(0).ToString(), mynode);rnrn rnrn rn catch (Exception ex)rn rn MessageBox.Show(ex.ToString());rn rn finallyrn rn conn.Close();rn rnrn rnrnrn 论坛

没有更多推荐了,返回首页