DataGridView绘制N层表头

一.设计时效果

 

二.运行时效果

1.表头立体效果

2.平面表头效果

三.简单谈谈实现原理

和前面的"也谈自动合计的Grid"原理类似,都是通过在一个control上绘制来达到目的,因为比较了内嵌控件或直接在DataGridView的列头上绘制的方法,都觉得不是很好或很容易实现,所以索性就直接在其他控件上实现了.当前可以作到实现任意层级的表头绘制,并且,当在用鼠标调整了列宽后会自动刷新绘制.当然,控件也存在几个问题,第1,不支持点击列排序,第2,不支持直接在列标题部分调整列宽.

四.部分源代码(控件调用方法)

 private void initdata()
        {
            DataTable tbl = new DataTable();
            tbl.Columns.Add("c1", typeof(string));
            tbl.Columns.Add("c2", typeof(string));
            tbl.Columns.Add("c3", typeof(string));
            tbl.Columns.Add("c4", typeof(string));
            tbl.Columns.Add("c5", typeof(string));
            tbl.Columns.Add("c6", typeof(string));
            tbl.Columns.Add("c7", typeof(string));
            tbl.Columns.Add("c8", typeof(string));
            tbl.Columns.Add("c9", typeof(string));
            tbl.Columns.Add("c10", typeof(string));
            tbl.Columns.Add("c11", typeof(string));
            tbl.Columns.Add("c12", typeof(string));

            tbl.Rows.Add(new object[] { "1","2","3","4","5","6","7","8","9","10","11","12"});
            this.jcsGrid1.DataGridView.DataSource = tbl.DefaultView;

            //this.gridHeader1.Grid = this.jcsDataGridView1.DataGridView;

            this.jcsGrid1.GirdHeader.AddDeepValue(0, 5, 1, "上半年");
            this.jcsGrid1.GirdHeader.AddDeepValue(6, 11, 1, "下半年");
            this.jcsGrid1.GirdHeader.AddDeepValue(0, 2, 2, "一季度");
            this.jcsGrid1.GirdHeader.AddDeepValue(3, 5, 2, "二季度");
            this.jcsGrid1.GirdHeader.AddDeepValue(6, 8, 2, "三季度");
            this.jcsGrid1.GirdHeader.AddDeepValue(9, 11, 2, "四季度");

            this.jcsGrid1.GirdHeader.AddDeepValue(0, 1, 3, "前2月");

            this.jcsGrid1.GirdHeader.DeepValue = 4;

            this.jcsGrid1.GirdHeader.ItemStyle = BorderStyle.Fixed3D;
            this.jcsGrid1.GirdHeader.IsDrawLeftHeader = true;
           
            //this.jcsDataGridView1.DataSource = tbl;
            //this.jcsGridControl1.DataSource = tbl;
        }

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值