DataGridView合并行.docVIP

  • 6
  • 0
  • 约1.28万字
  • 约 13页
  • 2017-12-12 发布于河南
  • 举报
DataGridView合并行

DataGridView 主要用到datagridview的单元格重画事件。 protected override void OnCellPainting(System.Windows.Forms.DataGridViewCellPaintingEventArgs e) 还有GDI画图, 复合表头如下图: 合并行的话同样是使用了其单元格重画事件:private void DrawCell(DataGridViewCellPaintingEventArgs e) 对上下单元格相同内容的合并。 同样是通过GDI实现。 具体的请见下面的源码 效果图如下: 复合表头源码如下: public partial class HeaderUnitView : DataGridView { private TreeView[] _columnTreeView; private ArrayList _columnList = new ArrayList(); private int _cellHeight = 17; public int CellHeight { get { return _cellHeight; } set { _cellHeight = value; } } private int _columnDeep = 1; private bool HscrollRefresh = false; /// summary /// 水平滚动时是否刷新表头,数据较多时可能会闪烁,不刷新时可能显示错误 /// /summary [Description(水平滚动时是否刷新表头,数据较多时可能会闪烁,不刷新时可能显示错误)] public bool RefreshAtHscroll { get { return HscrollRefresh; } set { HscrollRefresh = value; } } /// summary /// 构造函数 /// /summary public HeaderUnitView() { InitializeComponent(); this.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; //设置列高度显示模式 } [Description(设置或获得合并表头树的深度)] public int ColumnDeep { get { if (this.Columns.Count == 0) _columnDeep = 1; this.ColumnHeadersHeight = _cellHeight * _columnDeep; return _columnDeep; } set { if (value 1) _columnDeep = 1; else _columnDeep = value; this.ColumnHeadersHeight = _cellHeight * _columnDeep; } } [Description(添加合并式单元格绘制的所需要的节点对象)]

文档评论(0)

1亿VIP精品文档

相关文档