效果圖: ...
DataTable dt1 = new DataTable(); { dt1.Columns.Add("編號"); dt1.Columns.Add("姓名"); DataRow dr = dt1.NewRow(); dr[0] = "001"; dr[1] = "張三"; dt1.Rows.Add(dr); dr = dt1.NewRow(); dr[0] = "002"; dr[1] = "李四"; dt1.Rows.Add(dr); } DataTable dt2 = new DataTable(); { dt2.Columns.Add("編號"); dt2.Columns.Add("帳戶金額"); DataRow dr = dt2.NewRow(); dr[0] = "001"; dr[1] = "100000"; dt2.Rows.Add(dr); dr = dt2.NewRow(); dr[0] = "002"; dr[1] = "2000000"; dt2.Rows.Add(dr); } DataSet ds = new DataSet(); ds.Tables.Add(dt1); ds.Tables.Add(dt2); DataRelation relation = new DataRelation("帳戶信息", ds.Tables[0].Columns["編號"], ds.Tables[1].Columns["編號"]); ds.Relations.Add(relation); gridControl1.DataSource = ds.Tables[0];
效果圖: