XtraGrid中的gridControl中主细表问题
想实现主表是layoutView,一页只显示一行数据,细表是gridView,显示多行数据。比如人员档案,在layoutView中显示基本信息,比如照片、姓名等等,
在细表中显示其家庭成员,可能是多行数据,用gridView显示,
能在一个gridControl中实现吗?或者用什么正规的方式实现,谢谢。
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里实现
页:
[1]