首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

怎么让Winform的DataGridView合并表头

2013-06-19 
如何让Winform的DataGridView合并表头如何让winform 的DataGridView的列名合并。。如下图: ----------------

如何让Winform的DataGridView合并表头
如何让winform 的DataGridView的列名合并。。
如下图:
 ------------------------------
|    付款方式    |             |
 -----------------   销售员
|  现金 |  刷卡  |             |
--------------------------------

每一行为“付款方式”跨两列。。这两列的列名再分成两行。。
第二行再分成二列。。

[解决办法]
我想到一个方法,你可以把一个tableLayoutPanel放到你的列头(
[解决办法]
 现金 
[解决办法]
 刷卡 
[解决办法]
 
[解决办法]
)这两列上,来覆盖它,然后再用
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            if (e.RowIndex == -1 & e.ColumnIndex == 0)
            {
                Size dataGridViewSize = this.dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Size;
                Point p = this.dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Location;

                p.Offset(this.dataGridView1.Left + (dataGridViewSize.Width - 15) / 2, this.dataGridView1.Top + (dataGridViewSize.Height - 14) / 2);
                this.CheckBoxAll.Location = p;
                this.CheckBoxAll.Size = new Size(15, 14);
                this.CheckBoxAll.Visible = true;
                this.CheckBoxAll.BringToFront();
            }
        }
类似方式来做,一样可以,但是根本解决问题,我想你还是写一个类似于DataGridViewButtonCell和DataGridViewButtonColumn的两个来搞
[解决办法]
DataGridView 不支持合并列头的 你可以在一列中显示两列的数据 但要像web那种合并列头没有办法

参考 http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/fea3dcff-5447-450a-8f7c-bb1c4f63371d/
--------------------------------------------

热点排行