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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| private void InitDatabase()
{
DataSet dsMain = new DataSet();
DataTable dt1 = new DataTable("Nations");
dt1.Columns.Add("nCode", typeof(string));
dt1.Columns.Add("nName", typeof(string));
dt1.Rows.Add(new object[] { "1", "france" });
dt1.Rows.Add(new object[] { "2", "Italie" });
dt1.Rows.Add(new object[] { "3", "Espagne" });
dt1.Rows.Add(new object[] { "4", "Allemagne" });
dsMain.Tables.Add(dt1);
DataTable dt2 = new DataTable("States");
dt2.Columns.Add("sCode", typeof(string));
dt2.Columns.Add("sName", typeof(string));
dt2.Columns.Add("sNation", typeof(string));
dt2.Rows.Add(new object[] { "1", "Haute garonne", "1" });
dt2.Rows.Add(new object[] { "2", "Ariege", "1" });
dt2.Rows.Add(new object[] { "3", "Paris", "1" });
dt2.Rows.Add(new object[] { "4", "Rome", "2" });
dt2.Rows.Add(new object[] { "5", "Naples", "2" });
dt2.Rows.Add(new object[] { "6", "Madrid", "3" });
dt2.Rows.Add(new object[] { "7", "Barcelone", "3" });
dt2.Rows.Add(new object[] { "8", "Munich", "4" });
dt2.Rows.Add(new object[] { "9", "Baden Baden", "4" });
dt2.Rows.Add(new object[] { "10", "Ulm", "4" });
dsMain.Tables.Add(dt2);
dsMain.Relations.Add(new DataRelation("Membership", dsMain.Tables["Nations"].Columns["nCode"], dsMain.Tables["States"].Columns["sNation"]));
// Create dummy rows for any parent that has no children
//foreach (DataRow Row in dt1.Rows)
//{
// if (Row.GetChildRows("Membership").Length == 0)
// {
// DataRow s = dt2.NewRow();
// s["sCode"] = "";
// s["sName"] = "";
// s["sNation"] = Row["nCode"];
// dt2.Rows.Add(s);
// }
//}
dsMain.AcceptChanges();
cboNations.DataSource = dsMain;
cboNations.ValueMember = "Nations.nCode";
cboNations.DisplayMember = "Nations.nName";
cboStates.DataSource = dsMain;
cboStates.ValueMember = "Nations.Membership.sCode";
cboStates.DisplayMember = "Nations.Membership.sName";
} |
Partager