DevExpress GridControl gridView 主从表

来源:互联网 发布:mac只安装win10 编辑:程序博客网 时间:2024/05/21 17:27

 一 GriControl 设置主从表:

            DataSet ds = new DataSet();            //父GridView的数据            string sql = "select sc_prno,sc_prna from mespb04h";            DbHelperSQL.QueryD(sql,ds,"main");            //子GridView的数据            sql = "select pa_name,pa_no,sc_prno from mespb09h";            DbHelperSQL.QueryD(sql,ds,"son");            //这个是显示主从表的关键,一、GridControl通过检查DataSet.Relations的内容来分析数据            //二、关键名必须与设计GridView的层级关系的level name相同,否则,结果在意料之外。            DataRelation relation = new DataRelation("aa",                                                      ds.Tables["main"].Columns["sc_prno"],                                                      ds.Tables["son"].Columns["sc_prno"]);                        ds.Relations.Add(relation);            //这也是一个关键,不能直接设为:ds,必须指明到表。            gc1.DataSource = ds.Tables["main"];


 二,获取主表的当前选择行的某一列(如第0列)

三、获取从表的当前选择行的某一列(如ID列)
这个时候再使用获取主表当前选择行的某一列的方法是不行的,因为所得到的seletedrowscount=0。使用如下方法得到:
在MASTER表的展开事件中得到detail有的view.然后就可以利用它了。例: 

//主表的masterrowexpanded事件 private void gridView1_MasterRowExpanded(object sender, DevExpress.XtraGrid.Views.Grid.CustomMasterRowEventArgs e)        {            detailView = gridView1.GetDetailView(e.RowHandle, e.RelationIndex) as DevExpress.XtraGrid.Views.Grid.GridView;        } //取得从表的当前行int[] i = detailView.GetSelectedRows();            DataRowView dt = (DataRowView)detailView.GetRow(i[0]); //获得当前行某列的值可以使用dt["列名"].ToString();


0 0
原创粉丝点击