| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3219 人关注过本帖
标题:DataGridView如何实现双表头结构,求解?
只看楼主 加入收藏
anony
Rank: 2
等 级:论坛游民
帖 子:26
专家分:49
注 册:2009-10-26
结帖率:33.33%
收藏
已结贴  问题点数:20 回复次数:6 
DataGridView如何实现双表头结构,求解?
具体就是使表头实现多层结构的显示(不要用树结构)。具体就是一个标题占两列,下面各有一列不同表头
搜索更多相关主题的帖子: 表头 DataGridView 结构 求解 
2010-08-12 20:57
zhangkecd
Rank: 2
来 自:闲云工作室
等 级:论坛游民
帖 子:159
专家分:91
注 册:2009-3-13
收藏
得分:5 
这个可能要定制控件了。

闲云野鹤---梦想  
2010-08-12 22:42
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:5 
程序代码:
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            if (e.RowIndex == 0 && e.ColumnIndex >= 0)
            {
                int left = e.CellBounds.Left;
                int top = e.CellBounds.Top;
                int right = e.CellBounds.Right;
                int bottom = e.CellBounds.Bottom;
                e.Graphics.FillRectangle(new SolidBrush(Color.White), e.CellBounds);
                e.Handled = true;
                Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor);
                Pen gridLinePen = new Pen(gridBrush);
                e.Graphics.DrawLine(gridLinePen, right - 1,
                           top, right - 1,
                           bottom - 1);
                e.Graphics.DrawLine(gridLinePen, left,
                           bottom - 1, right,
                           bottom - 1);

                Brush b1 = new SolidBrush(Color.Black);
                e.Graphics.DrawString((String)e.Value, e.CellStyle.Font,
                                        b1, left + 2,
                                        top + 1, StringFormat.GenericDefault);

                Brush b2 = new SolidBrush(Color.Red);
                e.Graphics.DrawString((String)e.Value, e.CellStyle.Font,
                                        b2, left + 2,
                                        top + 10, StringFormat.GenericDefault);
            }

            DataGridViewSelectedCellCollection dgvscc = this.dataGridView1.SelectedCells;
            foreach (DataGridViewCell dgvc in dgvscc)
            {
                    if (e.RowIndex == 0
                        && e.RowIndex == dgvc.RowIndex
                        && e.ColumnIndex == dgvc.ColumnIndex)
                    {
                        int left = e.CellBounds.Left;
                        int top = e.CellBounds.Top;
                        int right = e.CellBounds.Right;
                        int bottom = e.CellBounds.Bottom;
                        // 绘制背景,覆盖单元格区域
                        e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(10,36,106)), e.CellBounds);
                       
                        // 绘制边框
                        Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor);
                        Pen gridLinePen = new Pen(gridBrush);
                        e.Graphics.DrawLine(gridLinePen, right - 1,
                                   top, right - 1,
                                   bottom - 1);
                        e.Graphics.DrawLine(gridLinePen, left,
                                   bottom - 1, right,
                                   bottom - 1);

                        // 绘制文字
                        Brush b1 = new SolidBrush(Color.White);
                        e.Graphics.DrawString((String)e.Value, e.CellStyle.Font,
                                                b1, left + 2,
                                                top + 1, StringFormat.GenericDefault);

                        Brush b2 = new SolidBrush(Color.White);
                        e.Graphics.DrawString((String)e.Value, e.CellStyle.Font,
                                                b2, left + 2,
                                                top + 10, StringFormat.GenericDefault);
                    }
            }

            e.Handled = true;           

        }


飘过~~
2010-08-13 09:53
zhangkecd
Rank: 2
来 自:闲云工作室
等 级:论坛游民
帖 子:159
专家分:91
注 册:2009-3-13
收藏
得分:0 
右学习了一招,感谢!

闲云野鹤---梦想  
2010-08-14 08:22
c1_wangyf
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:7
帖 子:665
专家分:2832
注 册:2010-5-24
收藏
得分:5 
3楼给了答案了,好好看看吧
2010-08-16 09:53
青春和谐号
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-5-14
收藏
得分:0 
这个能在access中用吗?

初来乍到 不发牢骚
见了高手 鞠躬脱帽
2011-05-15 18:52
快速回复:DataGridView如何实现双表头结构,求解?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018319 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved