Sharelai
博客园
首页
新随笔
新文章
联系
订阅
管理
posts - 7,comments - 5,trackbacks - 0
<
2007年6月
>
日
一
二
三
四
五
六
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
与我联系
发短消息
搜索
常用链接
我的随笔
我的空间
我的短信
我的评论
更多链接
我的参与
我的新闻
最新评论
我的标签
留言簿
(1)
给我留言
查看留言
我参加的小组
jQuery
Windows Embedded
我参与的团队
广州.NET俱乐部(0/1741)
asp.net开发团队(0/234)
随笔分类
winForm
随笔档案
2007年12月 (1)
2007年6月 (5)
2006年2月 (1)
文章分类
ASP.net
winForm
最新评论
阅读排行榜
1. DataGridView绑定(2806)
2. DataTable导出Excel(955)
3. 短信开发(289)
4. 后台更新UI界面(277)
5. Hashtable的应用(255)
评论排行榜
1. DataTable导出Excel(2)
2. 短信开发(2)
3. DataGridView绑定(1)
4. 晚安,2007!(0)
5. 后台更新UI界面(0)
DataGridView绑定
今早又一杰作,虽然不完美,但还凑合用,不作过多注释,给初学者动脑筋的机会,学会看懂别人的代码和思路,特别像我这些土代码,更可以磨练你的耐心 -_-#
1 Grid 实体类
1
public
class
GridEntity
2
{
3
public
GridEntity()
4
{
5
}
6
7
private
string
_GridName;
8
private
string
_DataPropertyName;
9
private
string
_HeaderText;
10
private
string
_ColumnType;
11
private
int
_Width;
12
private
bool
_IsFrozen;
13
private
int
_SortNo;
14
#region
15
/**/
///
<summary>
16
///
列表名
17
///
</summary>
18
public
string
GridName
19
{
20
set
21
{
22
_GridName
=
value;
23
}
24
get
25
{
26
27
if
(_GridName
==
null
)
28
{
29
return
null
;
30
}
31
else
32
{
33
return
_GridName.Trim();
34
}
35
}
36
}
37
#endregion
38
39
#region
40
/**/
///
<summary>
41
///
绑定字段名
42
///
</summary>
43
public
string
DataPropertyName
44
{
45
set
46
{
47
_DataPropertyName
=
value;
48
}
49
get
50
{
51
52
if
(_DataPropertyName
==
null
)
53
{
54
return
null
;
55
}
56
else
57
{
58
return
_DataPropertyName.Trim();
59
}
60
}
61
}
62
#endregion
63
64
#region
65
/**/
///
<summary>
66
///
列名
67
///
</summary>
68
public
string
HeaderText
69
{
70
set
71
{
72
_HeaderText
=
value;
73
}
74
get
75
{
76
77
if
(_HeaderText
==
null
)
78
{
79
return
null
;
80
}
81
else
82
{
83
return
_HeaderText.Trim();
84
}
85
}
86
}
87
#endregion
88
89
#region
90
/**/
///
<summary>
91
///
列类型
92
///
</summary>
93
public
string
ColumnType
94
{
95
set
96
{
97
_ColumnType
=
value;
98
}
99
get
100
{
101
102
if
(_ColumnType
==
null
)
103
{
104
return
null
;
105
}
106
else
107
{
108
return
_ColumnType.Trim();
109
}
110
}
111
}
112
#endregion
113
114
#region
115
/**/
///
<summary>
116
///
宽度
117
///
</summary>
118
public
int
Width
119
{
120
set
121
{
122
_Width
=
value;
123
}
124
get
125
{
126
return
_Width;
127
}
128
}
129
#endregion
130
131
#region
132
/**/
///
<summary>
133
///
列是否冻结
134
///
</summary>
135
public
bool
IsFrozen
136
{
137
set
138
{
139
_IsFrozen
=
value;
140
}
141
get
142
{
143
return
_IsFrozen;
144
145
}
146
}
147
#endregion
148
149
#region
150
/**/
///
<summary>
151
///
排序
152
///
</summary>
153
public
int
SortNo
154
{
155
set
156
{
157
_SortNo
=
value;
158
}
159
get
160
{
161
return
_SortNo;
162
}
163
}
164
#endregion
165
166
167
168
}
2 Grid操作类
public
class
GridBind
{
public
GridBind()
{
}
/**/
///
<summary>
///
给DataGridView添加列
///
</summary>
///
<param name="eDataGridView"></param>
///
<param name="eList"></param>
public
static
void
AddColumn(DataGridView eDataGridView, List
<
GridEntity
>
eList)
{
foreach
(GridEntity mGridEntity
in
eList)
{
eDataGridView.Columns.Add(getColumn(mGridEntity));
}
}
/**/
///
<summary>
///
取得要添加的列
///
</summary>
///
<param name="eGridEntity"></param>
///
<returns></returns>
private
static
DataGridViewColumn getColumn(GridEntity eGridEntity)
{
switch
(eGridEntity.ColumnType)
{
case
"
Bool
"
:
DataGridViewColumn mColBool
=
new
DataGridViewCheckBoxColumn();
mColBool.Name
=
eGridEntity.DataPropertyName;
mColBool.Da