如何让winform 的DataGridView的列名合并。。
如下图:
 ------------------------------
|    付款方式    |             |
 -----------------   销售员
|  现金 |   刷卡  |             |
-------------------------------- 每一行为“付款方式”跨两列。。这两列的列名再分成两行。。
第二行再分成二列。。

解决方案 »

  1.   

    我想到一个方法,你可以把一个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的两个来搞
      

  2.   

    DataGridView 不支持合并列头的 你可以在一列中显示两列的数据 但要像web那种合并列头没有办法参考 http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/fea3dcff-5447-450a-8f7c-bb1c4f63371d/
    --------------------------------------------------------------------------------