http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

12
返回列表 发新帖
楼主: wuguandi

[官方动态] 建议 :做个DataGridView增强类吧

[复制链接]
发表于 2013-11-15 10:06:28 | 显示全部楼层
wuguandi 发表于 2013-11-15 09:43
你百度下DataGridView多维表头,    有太多的人需要。这是很实用的东西。

在百度SO任何一个控件名都会有好多结果,呵呵

其实我的意思很明确,就是不做单一的组件,要做就做成套的,我的最新版皮肤里已加都加入了你说的这些功能,只是需要和皮肤一起使用,没有想过要单独出来。因为我认为成套的控件,应该会比单一的控件更实用。
再说如果你想单一的实现那就简单多了,
继承DataGridView,添加表头信息类。
  2,添加CellPainting,代码如下:
[C#] 纯文本查看 复制代码
private void DataGridViewEx_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
    if (e.RowIndex == -1)
    {
        //   int w = dataGridView1.HorizontalScrollingOffset + dataGridView1.TopLeftHeaderCell.Size.Width + dataGridView1.Columns[0].Width + 10;


        Rectangle newRect = new Rectangle(e.CellBounds.X + 1,
        e.CellBounds.Y + 1, e.CellBounds.Width - 4,
        e.CellBounds.Height - 4);

        using (
            Brush gridBrush = new SolidBrush(this.GridColor),
            backColorBrush = new SolidBrush(e.CellStyle.BackColor))
        {
            using (Pen gridLinePen = new Pen(gridBrush))
            {
                // Erase the cell.
                e.Graphics.FillRectangle(backColorBrush, e.CellBounds);

                // Draw the grid lines (only the right and bottom lines;
                // DataGridView takes care of the others).
                e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left,
                    e.CellBounds.Bottom - 1, e.CellBounds.Right - 1,
                    e.CellBounds.Bottom - 1);
                if (e.ColumnIndex > -1 && topRow != null && topRow.Cells[e.ColumnIndex].ColSpan > 1)
                {
                    e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1,
                        e.CellBounds.Top + e.ClipBounds.Height / 2, e.CellBounds.Right - 1,
                        e.CellBounds.Bottom);
                }
                else
                {
                    e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1,
                                                    e.CellBounds.Top, e.CellBounds.Right - 1,
                                                    e.CellBounds.Bottom);
                }

                // Draw the inset highlight box.
                //   e.Graphics.DrawRectangle(Pens.Blue, newRect);

                int scale = e.CellBounds.Height / 3;
                if (e.ColumnIndex > -1 && topRow.Cells[e.ColumnIndex].Text != null)
                {
                    scale = e.CellBounds.Height / 2;
                    e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom - e.CellBounds.Height / 2, e.CellBounds.Right, e.CellBounds.Bottom - e.CellBounds.Height / 2);
                }
                // Draw the text content of the cell, ignoring alignment.



                if (e.Value != null)
                {
                    e.Graphics.DrawString(e.Value.ToString(), e.CellStyle.Font,
                        Brushes.Crimson, e.CellBounds.X + 2,
                        e.CellBounds.Y + scale + 2, StringFormat.GenericDefault);



                }




                if (e.ColumnIndex > -1 && topRow.Cells[e.ColumnIndex].RelateIndex > -1 && topRow.Cells[e.ColumnIndex].Text != null)
                {
                    Rectangle recCell = new Rectangle(e.CellBounds.X - 1 - topRow.Cells[e.ColumnIndex].SpanRowWith,
    e.CellBounds.Y + 1, topRow.Cells[e.ColumnIndex].SpanRowWith,
    e.CellBounds.Height / 2);


                    StringFormat sf = new StringFormat();

                    sf.Alignment = StringAlignment.Center;


                    e.Graphics.DrawString(topRow.Cells[e.ColumnIndex].Text, e.CellStyle.Font, Brushes.Crimson, recCell, sf);

                }

                e.Handled = true;
            }
        }
    }

}
调用的方法
[C#] 纯文本查看 复制代码
dataGridViewEx1.TopRow.Cells[2].Text = "入库";
            dataGridViewEx1.TopRow.Cells[2].ColSpan = 2;


            dataGridViewEx1.TopRow.Cells[4].Text = "出库";
            dataGridViewEx1.TopRow.Cells[4].ColSpan = 2;

就这样就行了
而且博客园有同者写的挺 不错了,基本上够用了。
http://www.cnblogs.com/greatverve/archive/2012/03/05/multi-datagridview.html
我还是去研究我的皮肤吧,
你说的也不是不对,只是我是在想,如果我去开发一个这样的表格,说不定还没有第三方开发的好,因为人家毕竟研究了很久了。
所以我才坚持我的皮肤,而不是单一组件。
并不是不开发,而是不单一开发,要开发就是成套的控件


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
 楼主| 发表于 2013-11-19 14:41:17 | 显示全部楼层
谢谢站长。 开出一套的更好。谢谢站长,开发出来了要通知我哦
发表于 2013-11-19 14:47:04 | 显示全部楼层
你直接订阅,有更新我会发邮件通知http://www.sufeinet.com/click.php?key=sfljdksifsk9977998fklsj
 楼主| 发表于 2013-11-19 14:47:25 | 显示全部楼层
站长苏飞 发表于 2013-11-15 10:06
在百度SO任何一个控件名都会有好多结果,呵呵

其实我的意思很明确,就是不做单一的组件,要做就做成套 ...

谢谢站长。 开出一套的更好。谢谢站长,开发出来了要通知我哦
 楼主| 发表于 2013-11-19 14:48:09 | 显示全部楼层
站长苏飞 发表于 2013-11-19 14:47
你直接订阅,有更新我会发邮件通知http://www.sufeinet.com/click.php?key=sfljdksifsk9977998fklsj

好的
 楼主| 发表于 2013-11-19 14:50:59 | 显示全部楼层
站长苏飞 发表于 2013-11-19 14:47
你直接订阅,有更新我会发邮件通知http://www.sufeinet.com/click.php?key=sfljdksifsk9977998fklsj

我搜索研究了好多天,网上的多维表头的例子, 都存在问题。
第一:性能低,
第二:横向拖动表体时会闪,或列名会花掉
第三:竖向拖动,数据量大时,速度很慢很慢,很卡。
等等情况

你说的这种简单情况, 还有GDI绘的方法,还有用树做表头的方法,都研究过。所以,苦恼找不到一个比较好的
发表于 2013-11-19 14:53:40 | 显示全部楼层
wuguandi 发表于 2013-11-19 14:50
我搜索研究了好多天,网上的多维表头的例子, 都存在问题。
第一:性能低,
第二:横向拖动表体时会闪 ...

那是因为你没有找到解决的方法,或者是只是从网上复制一段,并没有真正理解或者,或许只需要修改一行小小的代码就可以了
 楼主| 发表于 2013-11-22 16:39:15 | 显示全部楼层
站长苏飞 发表于 2013-11-19 14:53
那是因为你没有找到解决的方法,或者是只是从网上复制一段,并没有真正理解或者,或许只需要修改一行小小 ...

是的,我没有找到解决的办法。  也正因为没有找到办法,所以来这论坛找你来了
发表于 2014-8-4 12:19:41 | 显示全部楼层
膜拜中……

其实我也需要这种表格的。原生的功能还是太少了
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-5-2 10:01

© 2014-2021

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