posts - 124,  comments - 29,  trackbacks - 0
1: 加GridLevelNode时注意加的位置!!!   不能一味的往顶层节点上加!
 2:一定要把新建的 view放到 viewCollection里面. this.gridControlUserTable.ViewCollection.Add(newGridView)
3:新建的关系名一定要和新建的level保持一致!!!!
4:注意GridView的更新(父GridView的更新)
  private void gridControlUserTable_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                //gridView  datatable  GridLevelNode都用同一个名字
                //ViewCaption中放类别, 1, 用户相关表.  0, 用户无关表
                GridView curView = (DevExpress.XtraGrid.Views.Grid.GridView)gridControlUserTable.FocusedView; //当前的GridView
                curView.MasterRowExpanding += new MasterRowCanExpandEventHandler(curView_MasterRowExpanding);
                curView.MasterRowExpanded += new CustomMasterRowEventHandler(curView_MasterRowExpanded);


                string viewName = curView.Name;
                string id = "view" + icount.ToString();
                int ihandle = curView.FocusedRowHandle; //当前的行号
                DataRow dr = curView.GetDataRow(ihandle); //当前的行


                GridView newGridView = null;
                DataTable newDataTable = null;
                DevExpress.XtraGrid.GridLevelNode gridLevel = null;
                icount++;
                #region 顶层的gridView
                if (curView.Name == "gridViewParent")//顶层的gridView
                {
                    string tableEName = dr["tableEName"].ToString();
                    string supplierRelated = dr["supplierRelated"].ToString();

                    #region 顶层
                    newGridView = new GridView();
                    newGridView.Name = id;
                    newGridView.OptionsView.ShowGroupPanel = false;
                    newGridView.OptionsBehavior.Editable = false;
                    newGridView.OptionsDetail.ShowDetailTabs = false;
                    newGridView.OptionsCustomization.AllowColumnMoving = false;
                    newGridView.OptionsBehavior.AutoExpandAllGroups = true;
                    this.gridControlUserTable.ViewCollection.Add(newGridView);

                    RelatedTableRecord[] relatedTableInfoArray = null;
                    UnrelatedTableRecord[] unRelatedTableInfoArray = null;
                    if (supplierRelated == "1")//厂商相关
                    {

                        relatedTableInfoArray = PublicFunction.GetRelatedTableInfos(tableEName, btime, etime);
                        if (relatedTableInfoArray == null || relatedTableInfoArray.Length == 0)
                        {
                            return;
                        }
                        CollectCommon.SetGridViewColumn(newGridView, "Config\\CollectMonitor\\supplierRelatedColumn.xml", "/Head");
                        newGridView.ViewCaption = "1";
                    }
                    else if (supplierRelated == "0")//厂商无关
                    {

                        unRelatedTableInfoArray = PublicFunction.GetUnRelatedTableInfos(tableEName, "", btime, etime);
                        if (unRelatedTableInfoArray == null || unRelatedTableInfoArray.Length == 0)
                        {
                            return;
                        }
                        CollectCommon.SetGridViewColumn(newGridView, "Config\\CollectMonitor\\supplierUnRelatedColumn.xml", "/Head");
                        newGridView.ViewCaption = "0";
                    }

                    newDataTable = new DataTable(id);
                    CollectCommon.SetDataTableColumn(newGridView, newDataTable);
                    if (supplierRelated == "1")//厂商相关
                    {
                        CollectCommon.FillTableData(newDataTable, relatedTableInfoArray);
                    }
                    else//厂商无关
                    {
                        CollectCommon.FillTableData(newDataTable, unRelatedTableInfoArray);
                    }
                    ds.Tables.Add(newDataTable);

                    gridLevel = new DevExpress.XtraGrid.GridLevelNode();
                    gridLevel.LevelTemplate = newGridView;
                    gridLevel.RelationName = id;

                    gridControlUserTable.LevelTree.Nodes.Add(gridLevel);

                    DataRelation dataRelation = new DataRelation(id, ds.Tables["parent"].Columns["tableEName"], ds.Tables[id].Columns["tableEName"], false);
                    ds.Relations.Add(dataRelation);

                    newGridView.RefreshData();
                    gridViewParent.RefreshData();

                    #endregion
                }
                #endregion
                #region 非顶层表
                else//非顶层表
                {
                    if (curView.ViewCaption == "1")//厂商相关表,再钻取最后一层,厂商无关的信息表,就钻取到头了.
                    {
                        #region
                        string tableEName = dr["tableEName"].ToString();
                        string supplier = dr["supplier"].ToString();
                        UnrelatedTableRecord[] unRelatedTableInfoArray = null;
                        unRelatedTableInfoArray = PublicFunction.GetUnRelatedTableInfos(tableEName, supplier, btime, etime);
                        if (unRelatedTableInfoArray == null || unRelatedTableInfoArray.Length == 0)
                        {
                            return;
                        }
                        newGridView = new GridView();
                        newGridView.Name = id;
                        newGridView.OptionsView.ShowGroupPanel = false;
                        newGridView.OptionsBehavior.Editable = false;
                        newGridView.OptionsDetail.ShowDetailTabs = false;
                        newGridView.OptionsCustomization.AllowColumnMoving = false;
                        newGridView.OptionsBehavior.AutoExpandAllGroups = true;
                        newGridView.ViewCaption = "0";
                        this.gridControlUserTable.ViewCollection.Add(newGridView);

                        CollectCommon.SetGridViewColumn(newGridView, "Config\\CollectMonitor\\supplierUnRelatedColumn.xml", "/Head");

                        newDataTable = new DataTable(id);
                        CollectCommon.SetDataTableColumn(newGridView, newDataTable);
                        CollectCommon.FillTableData(newDataTable, unRelatedTableInfoArray);

                        ds.Tables.Add(newDataTable);

                        gridLevel = new DevExpress.XtraGrid.GridLevelNode();
                        gridLevel.LevelTemplate = newGridView;
                        gridLevel.RelationName = id;

                        string parentTableName = curView.Name;
                        string parentLevelName = curView.Name;

                        //AddGridLevelNode(gridControlUserTable, parentLevelName, gridLevel);
                        
                        gridControlUserTable.LevelTree.Nodes[0].Nodes.Add(gridLevel);

                        DataColumn[] parentColumns = new DataColumn[2];
                        DataColumn[] childColumns = new DataColumn[2];
                        parentColumns[0] = ds.Tables[parentTableName].Columns["tableEName"];
                        parentColumns[1] = ds.Tables[parentTableName].Columns["supplier"];


                        childColumns[0] = ds.Tables[id].Columns["tableEName"];
                        childColumns[1] = ds.Tables[id].Columns["supplier"];

                        DataRelation dataRelation = new DataRelation(id, parentColumns, childColumns, false);
                        //DataRelation dataRelation = new DataRelation(id, parentColumns[0], childColumns[0], false);
                        ds.Relations.Add(dataRelation);
                        curView.RefreshData();
                        
                        #endregion
                    }
                    else if (curView.ViewCaption == "0")//厂商无关表
                    {

                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
            }
        }
posted on 2010-04-17 18:04 天书 阅读(4314) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



<2008年10月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(5)

随笔档案

文章分类

文章档案

好友的Bolg

搜索

  •  

最新评论

阅读排行榜

评论排行榜