DevExpress 中的gridControl1 中主从表的数据绑定

 //主表
            Medicine_ERP.BLL.Sell_Product sell = new BLL.Sell_Product();
            myDs = sell.GetList("1=1 order by  id desc");
            DataTable roleDt = myDs.Tables[0];
            roleDt.TableName = "Role";
            //myDs.Tables.Add(roleDt);

            if (roleDt.Rows.Count > 0)
            {
                //从表
                DataSet user = Maticsoft.DBUtility.DbHelperOleDb.Query(sbSQL.ToString());
                DataTable userDt = user.Tables[0];
                userDt.TableName = "User";
                user.Tables.Remove(userDt);
                myDs.Tables.Add(userDt);


                DataColumn keyColumn = myDs.Tables["Role"].Columns["ID"];         //主键
                DataColumn foreignColumn = myDs.Tables["User"].Columns["Sell_Id"];    //外键
                ///
                ///对于主从表,层次名至关重要,关系名必须和从表的层次名一致,
                ///否则从表显示的是从表的所有字段,而不是所设计的显示字段
                ///
                myDs.Relations.Add("销售明细", keyColumn, foreignColumn);     //从表的层次名
                gridControl1.DataSource = myDs.Tables["Role"];

你可能感兴趣的:(user,dataset)