- 积分
- 2
- 在线时间
- 21 小时
- 主题
- 1
- 注册时间
- 2014-10-24
- 帖子
- 18
- 最后登录
- 2015-1-20
- 帖子
- 18
- 软币
- 209
- 在线时间
- 21 小时
- 注册时间
- 2014-10-24
|
发表于 2014-11-27 17:07:55
|
显示全部楼层
private DataSet CreateDataSet()
{
DataSet ds = new DataSet();
DataTable Catagories = new DataTable();
Catagories.TableName = "Catagories";
Catagories.Columns.Add("CatagoryID", typeof(int));
Catagories.Columns.Add("CatagotyName", typeof(string));
Catagories.Rows.Add(new object[] { 1, "汽车" });
Catagories.Rows.Add(new object[] { 2, "飞机" });
Catagories.Rows.Add(new object[] { 3, "船" });
DataTable Products = new DataTable();
Products.TableName = "Products";
Products.Columns.Add("CatagoryID", typeof(int));
Products.Columns.Add("ProductID", typeof(int));
Products.Columns.Add("ProductName", typeof(string));
Products.Columns.Add("ProductPrice", typeof(decimal));
Products.Rows.Add(new object[]{1,11,"吉普",55});
Products.Rows.Add(new object[] { 1, 12, "奔腾",66 });
Products.Rows.Add(new object[] { 1, 13, "飞马" ,77});
Products.Rows.Add(new object[] { 2, 21, "波音",777 });
Products.Rows.Add(new object[] { 2, 22, "空客", 666 });
Products.Rows.Add(new object[] { 2, 23, "雷神", 767 });
Products.Rows.Add(new object[] { 3, 31, "渔船", 99 });
Products.Rows.Add(new object[] { 3, 32, "游船", 998 });
Products.Rows.Add(new object[] { 3, 33, "轮船", 797 });
ds.Tables.Add(Catagories);
ds.Tables.Add(Products);
DataTable Fruits = new DataTable();
Fruits.TableName = "Fruits";
Fruits.Columns.Add("CatagoryID", typeof(int));
Fruits.Columns.Add("FruitID", typeof(int));
Fruits.Columns.Add("FruitName", typeof(string));
Fruits.Rows.Add(new object[] { 1, 11, "苹果" });
Fruits.Rows.Add(new object[] { 2, 21, "菠萝" });
ds.Tables.Add(Fruits);
DataColumn keyColumn = ds.Tables["Catagories"].Columns["CatagoryID"];
DataColumn foreignKeyColumn = ds.Tables["Products"].Columns["CatagoryID"];
DataColumn foreignKeyColumn1 = ds.Tables["Fruits"].Columns["CatagoryID"];
ds.Relations.Add("CatagoriesProducts", keyColumn, foreignKeyColumn);
ds.Relations.Add("CatagoriesFruits", keyColumn, foreignKeyColumn1);
return ds;
}
private void Form1_Load(object sender, EventArgs e)
{
DataSet ds = CreateDataSet();
gridControl1.DataSource = ds.Tables["Catagories"];
gridControl1.ForceInitialize();
CardView cardView1 = new CardView(gridControl1);
gridControl1.LevelTree.Nodes.Add("CatagoriesProducts", cardView1);
//gridControl1.LevelTree.Nodes.Add("CatagoriesFruits", gridView2);
}
你看看这个吧
万全可以在一个GridControl里实现 |
|