dataGridView1.RowHeadersVisible = false;
把整行选中那一列去掉。如果需要整行选中,新增一按钮列模拟实现。
上源码:多维DataGridView

有个简易的方法:

1,继承DataGridView,添加表头信息类。
  2,添加CellPainting,代码如下:
(转)DataGridView多维表头及其扩展功能
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;
            }
        }
    }

}
(转)DataGridView多维表头及其扩展功能
3,调用方法
(转)DataGridView多维表头及其扩展功能  dataGridViewEx1.TopRow.Cells[2].Text = "入库";
(转)DataGridView多维表头及其扩展功能            dataGridViewEx1.TopRow.Cells[2].ColSpan = 2;
(转)DataGridView多维表头及其扩展功能
(转)DataGridView多维表头及其扩展功能
(转)DataGridView多维表头及其扩展功能            dataGridViewEx1.TopRow.Cells[4].Text = "出库";
(转)DataGridView多维表头及其扩展功能            dataGridViewEx1.TopRow.Cells[4].ColSpan = 2;
4,效果图
(转)DataGridView多维表头及其扩展功能

至于表尾合计,也做出了原型。二维表头+表尾合计,基本上满足需求了。

url:http://greatverve.cnblogs.com/archive/2012/03/05/Multi-DataGridView.html

1.DataGridView实现课程表 testcontrol.rar

(转)DataGridView多维表头及其扩展功能

2.DataGridView二维表头及单元格合并 DataGridView单元格合并和二维表头.rar myMultiColHeaderDgv.rar

(转)DataGridView多维表头及其扩展功能
(转)DataGridView多维表头及其扩展功能

(转)DataGridView多维表头及其扩展功能

3.DataGridView单元格显示GIF图片 gifanimationindatagrid.rar

(转)DataGridView多维表头及其扩展功能

4.自定义显示DataGridView列(行头显示行号与图标,同一单元格显示图片也显示文字)TestDataGridViewRowStyle2.rar

(转)DataGridView多维表头及其扩展功能

5.扩展DataGridView功能

(转)DataGridView多维表头及其扩展功能
(转)DataGridView多维表头及其扩展功能
(转)DataGridView多维表头及其扩展功能

相关文章

datagridview

DataGridView 说明

DataGridView绑定

DataGridView的一些技巧

DataGridView常见用法和FAQ汇总

CheckBox Header Column For DataGridView

DataGridView填充、更新、删除(多行)Sql Express 2005数据库

Datagridview 实现二维表头

如何于DataGridView中使用计算字段

DataGridView 数据绑定的一般过程

DataGridView扩展的一些想法(二维表头、合并单元格、合计行)

Winform DataGridView数据绑定问题

DataGridView分页功能的实现

WINFORM的DataGridView使用点滴

在DataGridView控件中加入ComboBox下拉列表框的实现

DataGridView中虚拟模式(Virtual Mode)的使用

C# DataGridView 小技巧

让DataGridView显示行号

DataGridView隔行显示不同的颜色

扩展 DataGridView 的功能(一)

从 DataGridView 控件 托放数据 到 TreeView控件

 

 

 

 

相关一些资料下载(收集自网络)

微软提供的例子                        datagridviewsamples.rar

DataGridView使用文档              DataGridView_Doc.rar

Excel与DataGridView互导数据    Excl导入datagridview.rar

DataGridView编程36计.pdf

DataGridView扩展功能代码
--------------------------------------------------------------------------
还有用第三方控件的:

在做信息管理系统时,很多中式报表都是多维的,要实现报表数据显示,通常要用到多维表头。然而,非常遗憾的是,Winform中DataGrid、DataGridView本身不提供多维表头设计,要实现多维报表只好利用第三方的控件。通过对DataGridView的扩展,利用标题行进行重绘,可实现多维表头的友好界面。下面是对多维表头的探讨和实现。

1、常用多表头制作方法

     a.第三方控件实现多维表头:FlexGrid--展示效果很好,就是数据量大加载时显示速度较慢。

     b.报表方式实现多维表头:CrystalReport、Grid++Report--通过预览方式实现数据显示

     c、DataGridView实现多维表头

2、DataGridView多维表头实现原理

     通过重绘标题栏进行多栏实现,通过RowSpan和ColSpan来进行合并,类似Html的Table实现方式。

3、调用方法 

        }

4、界面显示

(转)DataGridView多维表头及其扩展功能

      这段代码是两年前写的,由于当时时间和编程水平有限,很多代码段没有加注释,代码的可读性极差,只是为了达到效果,具体合并的实现方法自己也已模糊。

相关文章:

  • 2021-09-05
  • 2021-09-08
  • 2021-07-18
  • 2022-12-23
  • 2021-08-08
  • 2021-12-14
猜你喜欢
  • 2022-12-23
  • 2021-07-19
  • 2021-07-09
  • 2021-09-20
  • 2021-06-01
  • 2021-09-25
相关资源
相似解决方案