DataGridView
主要用到datagridview的单元格重画事件。
protected override void OnCellPainting(System.Windows.Forms.DataGridViewCellPaintingEventArgs e)
还有GDI画图,
复合表头如下图:
合并行的话同样是使用了其单元格重画事件:private void DrawCell(DataGridViewCellPaintingEventArgs e)
对上下单元格相同内容的合并。
同样是通过GDI实现。
具体的请见下面的源码
效果图如下:
复合表头源码如下:
1public partial class HeaderUnitView : DataGridView
2 {
3 private TreeView[] _columnTreeView;
4 private ArrayList _columnList = new ArrayList();
5申请微信账号 private int _cellHeight = 17;
6
7 public int CellHeight
8 {
9 get { return _cellHeight; }
10 t { _cellHeight = value; }
11 }
12 private int _columnDeep = 1;
13
14 private bool HscrollRefresh = fal;
15 /// <summary>
16 /// 水平滚动时是否刷新表头,数据较多时可能会闪烁,不刷新时可能显示错误
17 /// </summary>
18 [Description("水平滚动时是否刷新表头,数据较多时可能会闪烁,不刷新时可能显示错误")]
19 public bool RefreshAtHscroll
20 {
21 get { return HscrollRefresh; }
22 t { HscrollRefresh = value; }
23 }
24 /// <summary>
25 /// 构造函数
26 /// </summary>
27 public HeaderUnitView()
28 {
29 InitializeComponent();
30 this.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
31 //设置列高度显示模式
32 }
33
34 [Description("设置或获得合并表头树的深度")]
35 public int ColumnDeep
36 {
37 get make的现在分词
38 {
39 if (this.Columns.Count == 0)
40 _columnDeep = 1;
41
42 this.ColumnHeadersHeight = _cellHeight * _columnDeep;
43 return _columnDeep;
44 }
45
46 t
47 {
48 if (value < 1)
49 _columnDeep = 1;
50 el
51 _columnDeep = value;
52 this.ColumnHeadersHeight = _cellHeight * _columnDeep;
53 }
54 }
55
56
57 [Description("添加合并式单元格绘制的所需要的节点对象")]
58 public TreeView[] ColumnTreeView
59 {
腐竹怎么炒
60 get { return _columnTreeView; }
61 t
62 {
63 if (_columnTreeView != null)
64 {
65 for (int i = 0; i <= _columnTreeView.Length - 1; i++)
66 _columnTreeView[i].Dispo();
67 }
68 _columnTreeView = value;
69 }
70 }
71
72 [Description("设置添加的字段树的相关属性")]
73 public TreeView ColumnTreeViewNode
74 {
75 get { return _columnTreeView[0]; }
76 }
77
78 public ArrayList NadirColumnList
79 {
80 get
81 {
82 if (_columnTreeView == null)
83量子通信网 return null;
84
85 if (_columnTreeView[0] == null)
86 return null;
87
88 if (_columnTreeView[0].Nodes == null)
89 return null;
90
91 if (_columnTreeView[0].Nodes.Count == 0)
92 return null;
93
94 _columnList.Clear();
关于军训的作文95 GetNadirColumnNodes(_columnList, _columnTreeView[0].Nodes[0], fal);
96 return _columnList;
97 }
98 }
99///<summary>
100 ///绘制合并表头
101 ///</summary>
102 ///<param name="node">合并表头节点</param>
103 ///<param name="e">绘图参数集</param>
104 ///<param name="level">结点深度</param>
105 ///<remarks></remarks>
106 public 简单的灯笼怎么做void PaintUnitHeader(
107 TreeNode node,
108 System.Windows.Forms.DataGridViewCellPaintingEventArgs e,
109 int level)
110 {
111 //根节点时退出递归调用
112 妈妈不在家的日子if (level == 0)
113 return;
114
115火字旁的有什么字 RectangleF uhRectangle;
116 int uhWidth;
117 SolidBrush gridBrush = new SolidBrush(this.GridColor);
118 SolidBrush backColorBrush = new SolidBrush(e.CellStyle.BackColor);
119 Pen gridLinePen = new Pen(gridBrush);
120 StringFormat textFormat = new StringFormat();
121
122
123 textFormat.Alignment = StringAlignment.Center;
124
125 uhWidth = GetUnitHeaderWidth(node);