好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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然后绑定到控件中:

?

<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的结构         

?

public void loadxmltree(string xml)

    {

      xdocument xdoc = xdocument.parse(xml);

      treelistviewitem item = new treelistviewitem();

      string js" id="highlighter_213257">

?

private void treelistview1_beforeexpand(object sender, treelistviewcanceleventargs e)

    {

      if (e.item.imageindex == 0) e.item.imageindex = 1;

    }

你可以设置labeledit属性来激活或禁用编辑,treelistviewbeforelabelediteventargs参数提供了相应的属性值。   

?

private void treelistview1_beforelabeledit(object sender, treelistviewbeforelabelediteventargs e)

    {

      if (e.columnindex == 1)

      {

        combobox combobox = new combobox();

        combobox.items.addrange( new string[]{ "html" , "css" , "javascript" });

        e.editor = combobox;

      }

    }

treelistview开源你也可以根据自己的需要进行修改。

总结

以上所述是小编给大家介绍的c# winform treelistview的使用(treegridview),希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!

原文链接:http://HdhCmsTestcnblogs测试数据/liuxiaobo93/p/7942619.html?utm_source=tuicool&utm_medium=referral

dy("nrwz");

查看更多关于c# winform treelistview的使用(treegridview)实例详解的详细内容...

  阅读:52次