01.
string
connectionString =
"xxx"
;
02.
string
SQL =
"xxxxx"
;
03.
04.
05.
SqlConnection con =
new
SqlConnection(connectionString);
06.
SqlCommand com =
new
SqlCommand(SQL, con);
07.
SqlDataAdapter adapter =
new
SqlDataAdapter(com);
08.
09.
try
10.
{
11.
12.
adapter.Fill(ds,
"Detail"
);
13.
14.
com.CommandText = commandSql;
15.
16.
adapter.Fill(ds,
"Master"
);
17.
}
18.
finally
19.
{
20.
con.Close();
21.
}
22.
23.
24.
dvgMaster.DataSource = ds.Tables[
"Master"
].DefaultView;
25.
26.
dvgDetail.DataSource = ds.Tables[
"Detail"
].DefaultView;
27.
28.
29.
BindingManagerBase currency;
30.
currency =
this
.BindingContext[dvgMaster.DataSource];
31.
currency.PositionChanged +=
new
System.EventHandler(
this
.Binding_PositionChanged);
32.
}
33.
private
void
Binding_PositionChanged(
object
sender, EventArgs e)
34.
{
35.
string
filter;
36.
DataRowView selectedRow;
37.
38.
39.
selectedRow = (DataRowView)
this
.BindingContext[dvgMaster.DataSource].Current;
40.
41.
42.
filter =
"No='"
+ selectedRow[
"No"
].ToString() +
"'"
;
43.
44.
45.
ds.Tables[
"Detail"
].DefaultView.RowFilter = filter;
46.
}