Devexpress使用之:TreeList控件

http://www.cnblogs.com/habin/archive/2009/04/15/1436418.html


Devexpress系列控件功能很强大,使用起来也不太容易,我也是边摸索边使用,如果有时间我会把常用控件的使用方法整理出来的。

 
Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraTreeList.Nodes;

namespace TreeListDemo1
{
    public partial class Form1 : Form
    {
        private string[] rootNames;
        private string[] root = new string[] { "AAA", "BBB\\", "CCC", "DDD", "EEE" };

        public Form1()
        {
            InitializeComponent();

            //初始化TreeList控件
            CreateArrayWithNames();
            AppendNodes(rootNames, null, "", "");
        }

        #region 自定义函数
        //创建节点数组
        private void CreateArrayWithNames()
        {
            rootNames = new string[root.Length];
            for (int i = 0; i < root.Length; i++)
                rootNames[i] = root[i];
        }

        //追加节点
        private void AppendNodes(string[] names, TreeListNode aNode, string root, string root2)
        {
            Cursor currentCursor = Cursor.Current;
            Cursor.Current = Cursors.WaitCursor;

            treeList1.BeginUnboundLoad();
            TreeListNode node = null;
            foreach (string s in names)
            {
                if (s.EndsWith("\\"))
                {

                    node = treeList1.AppendNode(new object[] { s.Substring(0, s.Length - 1) }, aNode);
                    aNode = node;

                }
                else
                {
                    node = treeList1.AppendNode(new object[] { s }, aNode);
                }

                node.Tag = true;

            }
            treeList1.EndUnboundLoad();

            Cursor.Current = currentCursor;
        }

        //获取节点名称
        private string FullNameByNode(TreeListNode node, int columnId)
        {
            string ret = node.GetValue(columnId).ToString();
            while (node.ParentNode != null)
            {
                node = node.ParentNode;
                ret = node.GetValue(columnId).ToString() + "\\" + ret;
            }
            return ret;
        }
#endregion

        private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
        {
            string s = FullNameByNode(e.Node, 0);
            this.Text = s;
        }
    }
}

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值