01.
private
void
loaddata() {
02.
03.
DataGridViewCheckBoxColumn colStatus =
new
DataGridViewCheckBoxColumn();
04.
05.
colStatus.Name =
"Status"
;
06.
07.
colStatus.HeaderText =
"Status"
;
08.
09.
dataGridView1.Columns.Add(colStatus);
10.
11.
SqlConnection db =
new
SqlConnection(conn);
12.
13.
StringBuilder sb =
new
StringBuilder();
14.
sb.AppendLine(
" SELECT [St_ID] "
);
15.
sb.AppendLine(
" ,[St_Yard] "
);
16.
sb.AppendLine(
" FROM [Cust].[dbo].[T_Stock] "
);
17.
sb.AppendLine(
" WHERE Fab_ID = 1 "
);
18.
19.
SqlDataAdapter da =
new
SqlDataAdapter(sb.ToString(), db);
20.
DataSet ds =
new
DataSet();
21.
da.Fill(ds,
"Cust"
);
22.
23.
DataSet ds1 =
new
DataSet();
24.
25.
26.
dataGridView1.DataSource = ds;
27.
dataGridView1.DataMember =
"Cust"
;
28.
29.
30.
31.
32.
33.
34.
35.
36.
dataGridView1.AllowUserToAddRows =
false
;
37.
38.
dataGridView1.Columns[
"St_Yard"
].DefaultCellStyle.Format =
"#,###"
;
39.
}
40.
41.
private
void
button1_Click(
object
sender, EventArgs e) {
42.
loaddata();
43.
}
44.
45.
private
void
button2_Click(
object
sender, EventArgs e) {
46.
if
(dataGridView1.RowCount <= 0)
47.
return
;
48.
49.
50.
foreach
(DataGridViewRow r
in
dataGridView1.Rows) {
51.
52.
53.
if
(r.Cells[
"Status"
].Value ==
"True"
) {
54.
var _with1 = dataGridView2;
55.
int
rc = dataGridView2.RowCount;
56.
_with1.Rows.Add();
57.
_with1.Rows[rc].Cells[
"Status"
].Value = r.Cells[
"Status"
].Value;
58.
_with1.Rows[rc].Cells[
"St_ID"
].Value = r.Cells[
"St_ID"
].Value;
59.
_with1.Rows[rc].Cells[
"St_Yard"
].Value = r.Cells[
"St_Yard"
].Value;
60.
}
61.
}
62.
63.
for
(
int
i = dataGridView1.RowCount - 1; i >= 0; i += -1) {
64.
if
(dataGridView1.Rows[i].Cells[
"Status"
].Value ==
"True"
) {
65.
dataGridView1.Rows.RemoveAt(i);
66.
}
67.
}
68.
}