FineUI 官方论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

本论坛已关闭(禁止注册、发帖和回复)
请移步 三石和他的朋友们

FineUI首页 WebForms - MVC & Core - JavaScript 常见问题 - QQ群 - 十周年征文活动

FineUI(开源版) 下载源代码 - 下载空项目 - 获取ExtJS - 文档 在线示例 - 版本更新 - 捐赠作者 - 教程

升级到 ASP.NET Core 3.1,快、快、快! 全新ASP.NET Core,比WebForms还简单! 欢迎加入【三石和他的朋友们】(基础版下载)

搜索
查看: 3476|回复: 3
打印 上一主题 下一主题

扩充一下树控件让你的使用更方便.

[复制链接]
跳转到指定楼层
楼主
发表于 2012-6-12 02:48:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
大家在使用树控件时可能会使用到父节点及节点索引等一些常用属性,在这我们就对树相关的类进行一下扩展.
修改内容仅供学习参考,请大家不要随意对ExtAspNet的源码进行修改,因为咱们要尊重开发者的劳动成果.如果版主觉得可以的话,建议增加一下这些属性方便大家使用,让ExtAspNet越来越好.
ExtAspNet\WebControls\PanelBase.CollapsablePanel.Tree\TreeNode\TreeNode.cs:
(1).增加
    /// <summary>
    /// 获取当前节点索引值
    /// </summary>
    public int Index { get; internal set; }

    /// <summary>
    /// 获取父节点
    /// </summary>
    public TreeNode ParentNode { get; internal set; }
----------------------------------------------------------------------------------------------------------------------------------------------------
ExtAspNet\WebControls\PanelBase.CollapsablePanel.Tree\Tree.cs:
(1).增加
    /// <summary>
    /// 获取当前选中的树节点
    /// </summary>
    public TreeNode SelectedNode
    {
        get
        {
            return this.FindNode(this.SelectedNodeID);
        }
    }

2.ExtAspNet\WebControls\PanelBase.CollapsablePanel.Tree\TreeNode\TreeNodeCollection.cs:
(1).增加定义
    TreeNode owner;
  
(2).修改构造函数为
    public TreeNodeCollection(Tree tree, TreeNode owner)
    {
        this._treeInstance = tree;
        this.owner = owner;
    }
(3).增加
    public new void Add(TreeNode item)
    {
        item.ParentNode = owner;
        item.Index = this.Count;
        if(owner!=null)
        {
            if (owner.Leaf)
            {
                owner.Leaf = false;
            }
        }

        base.Add(item);
    }
        
    public new void Remove(TreeNode item)
    {
        int index = item.Index;
        for (int i = index; i < this.Count; i++)
        {
            this.Index = this.Index - 1;
        }

        if (owner != null)
        {
            if (owner.Nodes.Count==0 && owner.Leaf==false)
            {
                owner.Leaf = true;
            }
        }

        base.Remove(item);
    }

    public new void RemoveAt(int index)
    {
         for (int i = index; i < this.Count; i++)
        {
            this.Index = this.Index - 1;
        }

        if (owner != null)
        {
            owner.Leaf = owner.Nodes.Count == 0 && !owner.Leaf;           
        }

        base.RemoveAt(index);
    }
        
(4).将原有的protected override void InsertItem(int index, TreeNode item)方法修改为
    protected override void InsertItem(int index, TreeNode item)
    {
        if (_treeInstance != null)
        {
            ResolveTreeNode(item);
        }

        for (int temp = index; temp < Count; temp++)
        {
            this[temp].Index = index;
        }

        item.Index = index;
        if (owner != null && owner.Leaf)
        {
            owner.Leaf = false;
        }

         base.InsertItem(index, item);
    }
沙发
发表于 2012-6-12 03:22:02 来自手机 | 只看该作者
多谢,我测试后会加入下个版本中。
板凳
发表于 2012-6-23 14:26:29 | 只看该作者
V3.1.8中会增加ParentNode
地板
发表于 2012-10-8 15:54:11 | 只看该作者
我天,搞了大半宿,最不愿做的事情就是 去动手该源码,命苦了
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|FineUI 官方论坛 ( 皖ICP备2021006167号-1 )

GMT+8, 2024-5-14 07:28 , Processed in 0.045816 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表