DataTable table1 = new DataTable();
table1.Columns.Add("A");
table1.Columns.Add("B");
table1.Columns.Add("Z");
table1.Rows.Add(1, "foo", 1);
table1.Rows.Add(2, "bar", 2);
table1.Rows.Add(3, "baz", 3);
table1.AcceptChanges();
DataTable table2 = new DataTable();
table2.Columns.Add("A");
table2.Columns.Add("B");
table2.Rows.Add(1, "FOO");
table2.Rows.Add(2, "BAR");
table2.Rows.Add(3, "BAZ");
table2.AcceptChanges();
DataSet dataSet = new DataSet();
dataSet.Tables.Add(table1);
dataSet.Tables.Add(table2);
dataSet.Relations.Add(new DataRelation("rel",
table1.Columns["A"],
table2.Columns["A"]));
DataView dataView = new DataView(
table1, "Z > 0", "Z", DataViewRowState.CurrentRows);
//DataGridView.DataSource = dataView;
//DataGridView.Columns["Z"].Visible = false;
foreach (DataRowView rowView in dataView)
{
Debug.Print(rowView.Row["B"].ToString() + " " +
rowView.Row.RowState.ToString() + " " +
rowView.Row.GetChildRows("rel")[0]["B"].ToString() + " " +
rowView.Row.GetChildRows("rel")[0].RowState.ToString());
}
//foo Unchanged FOO Unchanged
//bar Unchanged BAR Unchanged
//baz Unchanged BAZ Unchanged
foreach (DataRow row in table1.Rows)
{
row["Z"] = 0;
}
int i = 1;
foreach (DataRowView rowView in new DataView(
table2, "B LIKE 'B*'", "B DESC", DataViewRowState.CurrentRows))
{
rowView.Row.GetParentRow("rel")["Z"] = i;
i++;
}
foreach (DataRowView rowView in dataView)
{
Debug.Print(rowView.Row["B"].ToString() + " " +
rowView.Row.RowState.ToString() + " " +
rowView.Row.GetChildRows("rel")[0]["B"].ToString() + " " +
rowView.Row.GetChildRows("rel")[0].RowState.ToString());
}
//baz Modified BAZ Unchanged
//bar Modified BAR UnchangedDataTable table1 = new DataTable();
table1.Columns.Add("A");
table1.Columns.Add("B");
table1.Rows.Add(1, "foo");
table1.Rows.Add(2, "bar");
table1.Rows.Add(3, "baz");
table1.AcceptChanges();
DataTable table2 = new DataTable();
table2.Columns.Add("A");
table2.Columns.Add("B");
table2.Columns.Add("Z", System.Type.GetType("System.Decimal"));
table2.Rows.Add(1, "FOO", 1);
table2.Rows.Add(2, "BAR", 2);
table2.Rows.Add(3, "BAZ", 3);
table2.AcceptChanges();
DataSet dataSet = new DataSet();
dataSet.Tables.Add(table1);
dataSet.Tables.Add(table2);
dataSet.Relations.Add(new DataRelation("rel",
table1.Columns["A"],
table2.Columns["A"]));
table1.Columns.Add("Y");
table1.Columns["Y"].Expression = "Min(Child.Z)";
DataView dataView = new DataView(
table1, "Y > 0", "Y", DataViewRowState.CurrentRows);
//DataGridView.DataSource = dataView;
//DataGridView.Columns["Y"].Visible = false;
foreach (DataRowView rowView in dataView)
{
Debug.Print(rowView.Row["B"].ToString() + " " +
rowView.Row.RowState.ToString() + " " +
rowView.Row.GetChildRows("rel")[0]["B"].ToString() + " " +
rowView.Row.GetChildRows("rel")[0].RowState.ToString());
}
//foo Unchanged FOO Unchanged
//bar Unchanged BAR Unchanged
//baz Unchanged BAZ Unchanged
foreach (DataRow row in table2.Rows)
{
row["Z"] = 0;
}
int i = 1;
foreach (DataRowView rowView in new DataView(
table2, "B LIKE 'B*'", "B DESC", DataViewRowState.CurrentRows))
{
rowView.Row["Z"] = i;
i++;
}
foreach (DataRowView rowView in dataView)
{
Debug.Print(rowView.Row["B"].ToString() + " " +
rowView.Row.RowState.ToString() + " " +
rowView.Row.GetChildRows("rel")[0]["B"].ToString() + " " +
rowView.Row.GetChildRows("rel")[0].RowState.ToString());
}
//baz Unchanged BAZ Modified
//bar Unchanged BAR Modified