代码
1
public
Card(
string
a,
string
b,
string
c)
2
{
3
InitializeComponent();
4
//
传进来的(ABCDEFG……)
5
label1.Text
=
a;
6
//
传进来的随机数字符串
7
label2.Text
=
b;
8
//
序列号也是传进来的随机数字符串数组
9
label3.Text
=
c;
10
}
11
//
生成密保卡
12
public
void
createtable(
string
X,
string
Axis)
13
{
14
this
.dataGridView1.Columns.Clear();
15
this
.dataGridView1.Rows.Clear();
16
//
声明一个字符数组tmpChars/X.ToCharArray方法将X字符串变成字符数组
17
char
[] tmpChars
=
X.ToCharArray();
18
//
用“_”将tmpAxises分割
19
string
[] tmpAxises
=
Axis.Split(
new
string
[]{
"
_
"
}, StringSplitOptions.RemoveEmptyEntries);
20
21
//
datagridview中添加一空列,操作列名columnName,操作列名为空
22
this
.dataGridView1.Columns.Add(
"
columnName
"
,
""
);
23
//
循环添加列,并对显示列名赋值。
24
for
(
int
i
=
0
; i
<
tmpChars.Length; i
++
)
25
{
26
this
.dataGridView1.Columns.Add(
"
columnName
"
+
i ,tmpChars[i].ToString());
27
}
28
//
构造8行(提前固定的)10列(X中的字符数目)的矩阵并填充数据
29
//
行循环
30
for
(
int
i
=
0
; i
<
8
; i
++
)
31
{
32
DataGridViewRow dgvRow
=
new
DataGridViewRow();
33
ArrayList list
=
new
ArrayList();
34
//
列循环
35
for
(
int
j
=
0
; j
<
this
.dataGridView1.Columns.Count; j
++
)
36
{
37
//
***********设置行单元格容器为textBox
38
dgvRow.Cells.Add(
new
DataGridViewTextBoxCell());
39
//
添加每行的第一个单元格的值即行号
40
if
(j
==
0
)
41
{
42
list.Add(i
+
1
);
43
}
44
//
每一行的其他单元格值
45
else
46
{
47
list.Add(tmpAxises[(j
-
1
)
*
8
+
i]);
48
}
49
}
50
//
用设置的值填充当前行。list.ToArray()是将list由ArrayList变成object数组
51
dgvRow.SetValues(list.ToArray());
52
//
将当前行填充至datagridview中。
53
this
.dataGridView1.Rows.Add(dgvRow);
54
}
55
//
填充表
56
}
转载于:https://www.cnblogs.com/angleSJW/archive/2009/12/17/1626079.html
相关资源:DataGridView表头添加checkbox实现全选反选