这篇文章主要介绍了c# winform treelistview的使用(treegridview),本文通过实例代码给大家详细介绍,需要的朋友可以参考下
正文
c# winform treelistview的使用(treegridview)实例详解
treeview控件显示的内容比较单一,如果需要呈现更详细信息treelistview是一个不错的选择。
先看效果:
首先需要引用文件system.windows.forms.treelistview.dll、system.runtime.interopservices.apis.dll
你可以将treelistview加入到工具箱中然后在添加到窗体中。
1.你需要添加列
2.你需要添加一个imagelist作为节点图标的容器(你还需要配置treelistview的smallimagelist属性为imagelist控件的id)
3.现在可以给控件绑定数据了
此控件比较适合呈现具有父子级关系的复杂数据结构,当然也包含xml格式的数据
下面尝试解析一个设备树xml然后绑定到控件中:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
<device name= "hidc-1600tv _192.168.230.188" itemtype= "dvr" type= "onvif" typeid= "" code= "" location= "" description= "" id= "" uniqueid= "192.168.230.188" > <ip value= "192.168.230.188" /> <port value= "80" /> <username value= "admin" /> <password value= "1234" /> <authenaddress value= "/" /> <authenmode value= "1" /> <onvifuser value= "admin" /> <onvifpwd value= "1234" /> <onvifaddress value= "/onvif/device_service" /> <rtspuser value= "admin" /> <rtsppwd value= "1234" /> <childdevices> <device name= "" itemtype= "channel" type= "" typeid= "" code= "" location= "" description= "" id= "" uniqueid= "" > <ptzenable value= "true" /> <ptz1 value= "5" /> <ptz2 value= "15" /> <ptz3 value= "25" /> <ptz4 value= "35" /> <ptz5 value= "45" /> <ptz6 value= "55" /> <ptz7 value= "65" /> <ptz8 value= "75" /> <ptz9 value= "85" /> <childdevices> <device name= "" itemtype= "rstreamer" type= "" typeid= "1" code= "" location= "" description= "" id= "" > <mediaprofile value= "1" /> <multicast value= "false" /> </device> <device name= "" itemtype= "rstreamer" type= "" typeid= "2" code= "" location= "" description= "" id= "" > <mediaprofile value= "2" /> <multicast value= "false" /> </device> </childdevices> </device> </childdevices> </device> |
使用递归算法很容易提取xml的结构
发表评论