找回密码
 立即注册

QQ登录

只需一步,快速开始

gj_fwd

论坛元老

7

主题

25

帖子

6035

积分

论坛元老

积分
6035

活字格认证

gj_fwd
论坛元老   /  发表于:2014-3-21 00:01  /   查看:10841  /  回复:19
科目编码 科目名称
102 银行存款
10201 中行
10201001 中行太原支行
10201002 中行古交支行
10202 工行
10202001 工行太原支行
10202002 工行迎泽区运行
....
请问如何在c1FlexGrid中如何根据上下级科目进行树型显示呢?在示例看到是关于主从表的!

19 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2014-3-21 09:16:00
沙发
回复 1楼gj_fwd的帖子

可以参考链接中文章:http://blog.gcpowertools.com.cn/ ... d_win_subtotal.aspx

看能否满足你的需求。
回复 使用道具 举报
gj_fwd
论坛元老   /  发表于:2014-3-21 09:48:00
板凳
上面方法是用于增加分类统计合计行,而我的要求是不增加统计行,再帮我看看。
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2014-3-21 15:24:00
地板
回复 3楼gj_fwd的帖子

你好,
链接中文章展示了两个效果,分组和合计。去掉合计功能,分组功能是你期望的效果吗?

或者期望效果如图:


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
gj_fwd
论坛元老   /  发表于:2014-3-21 16:03:00
5#
功能已以实现。  


    public partial class Form1 : Form
    {
        public Form1() {
            InitializeComponent();
            grid.Tree.Column = 0;
            grid.Rows.Count = 1;
            grid.Rows[0][0] = "会计科目";
            grid.Cols[0].Width = 250;

            ZwDataContext zw = new ZwDataContext();
            list = zw.diKm.Where(r => r.KjYear == 2013).ToList();

            //grid.DataSource = new BindingSource(list, ""); // 使用绑定数据源时
            list.Where(r => r.Kmdm.Length == 3).ToList().ForEach(r => AddNode(r));
        }

        private int[] KmLen = { 3, 5, 8 };  // 各级科目宽度
        private List<diKm> list;            // 科目列表

        private void AddNode(diKm km) {
            int level = Array.IndexOf(KmLen, km.Kmdm.Length);
            if (level == KmLen.Length - 1) { return; } //末级时退出
            var q = from r in list
                    where r.Kmdm.Length == KmLen[level + 1] &amp;&amp; r.Kmdm.Substring(0, KmLen[level]) == km.Kmdm
                    select r;
            var temp = q.ToList();
            // Row row = grid.Rows[list.IndexOf(km)];  // 使用绑定源时用
            Row row = grid.AddItem(new object[] { km.Kmdm + " " + km.Kmmc }); // 不使用绑定源时用
            row.IsNode = temp.Count > 0;   //  使用绑定源时此句报 Action not supported in bound mode.
            if (row.IsNode) { row.Node.Level = level; }
            temp.ForEach(r => AddNode(r));
        }
    }
只是使用绑定数据源时报错。帮我看一下。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2014-3-21 16:39:00
6#
回复 5楼gj_fwd的帖子

好的,感谢反馈。我稍后尝试重现问题
回复 使用道具 举报
gj_fwd
论坛元老   /  发表于:2014-3-21 18:33:00
7#
前面那个有问题


    public partial class Form1 : Form
    {
        public Form1() {
            InitializeComponent();
            grid.Tree.Column = 0;
            grid.Rows.Count = 1;
            grid.Rows[0][0] = "会计科目";
            grid.Rows[0][1] = "期初金额";

            grid.Cols[0].Width = 250;

            ZwDataContext zw = new ZwDataContext();
            kmALL = zw.diKm.Where(r => r.KjYear == 2013).OrderBy(r => r.Kmdm).ToList();

            //grid.DataSource = new BindingSource(list, ""); // 使用绑定数据源时

            AddCategory("1", "资产类");
            AddCategory("2", "负债类");
            AddCategory("3", "所有者权益类");
            AddCategory("4", "成本类");
            AddCategory("5", "损益类");
        }

        private int[] KmLen = { 3, 5, 8 };  // 各级科目宽度
        private List<diKm> kmALL;           // 科目列表

        private void AddCategory(string category, string desc) {
            Row row = grid.AddItem(desc);
            row.AllowEditing = false;
            row.IsNode = true;
            var q = kmALL.Where(r => r.Kmdm.Substring(0, 1) == category &amp;&amp; r.Kmdm.Length == KmLen[0]);
            q.ToList().ForEach(r => AddChildsNode(r, row.Node));
        }

        private void AddChildsNode(diKm km, Node parent) {
            Bitmap bp = Resources.Km;
            bp.MakeTransparent(Color.Fuchsia);
            Node node = parent.AddNode(NodeTypeEnum.LastChild, km.Kmdm + " " + km.Kmmc, km, bp);
            int level = Array.IndexOf(KmLen, km.Kmdm.Length);
            if (level + 1 < KmLen.Length) {
                var childs = kmALL.Where(r => r.Kmdm.Length == KmLen[level + 1] &amp;&amp;
                    r.Kmdm.Substring(0, km.Kmdm.Length) == km.Kmdm).ToList();
                childs.ForEach(r => AddChildsNode(r, node));
            }
        }

    }

有个问题,就是如何将Node.Row绑定到数据源, 如果先将grid绑定到数据源,那设置Row.IsNode会报错。查过文档,这个节点属性不支持绑字数据行,有什么办法吗?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2014-3-24 14:48:00
8#
回复 7楼gj_fwd的帖子

当前我无法运行这段代码,能否把 diKm 类补发上来?
回复 使用道具 举报
gj_fwd
论坛元老   /  发表于:2014-3-24 17:26:00
9#
这是源码!帮我看看.

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2014-3-24 18:48:00
10#
回复 9楼gj_fwd的帖子

感谢提供 Demo ,我调试后反馈给你。
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部