Example #1
0
            /// <summary>
            /// 该节点是否为某一级节点的最后一个子结点
            /// </summary>
            /// <param name="level">节点层级</param>
            /// <returns></returns>
            private bool IsLastCell(int level)
            {
                int row = DataGridView.Rows.GetNextRow(RowIndex, DataGridViewElementStates.None);

                if (row == -1)
                {
                    return(true);
                }
                DataGridViewGroupCell cel = DataGridView.Rows[row].Cells[0] as DataGridViewGroupCell;

                return(cel.GroupLevel == level);
            }
Example #2
0
        private void ShowNodes(XmlNode root, DataGridViewGroupCell item)
        {
            if (root.HasChildNodes)
            {
                int                     i    = 0;
                XmlNodeList             xnf  = root.ChildNodes;
                DataGridViewGroupCell[] cell = new DataGridViewGroupCell[xnf.Count];
                foreach (XmlNode xn in xnf)
                {
                    switch (xn.NodeType)
                    {
                    case XmlNodeType.Element:
                        XmlElement xe = (XmlElement)xn;
                        //设置属性值
                        xe.SetAttribute("RowNum", Convert.ToString(rownum));
                        cell[i] = grid.Rows[rownum].Cells[0] as DataGridViewGroupCell;
                        item.AddChildCell(cell[i]);
                        //   grid.Rows[rownum].Cells[0].Value = xe.Name + xe.GetAttribute("RowNum"); ;
                        grid.Rows[rownum].Cells[0].Value = xe.Name;
                        //      grid.Rows[rownum].Cells[0].Value = xe.GetAttribute("name");
                        grid.Rows[rownum].Cells[1].Value = xe.GetAttribute("name");
                        grid.Rows[rownum].Cells[2].Value = xe.Value;
                        grid.Rows[rownum].Cells[3].Value = xe.GetAttribute("width");   //字节
                        grid.Rows[rownum].Cells[4].Value = xe.GetAttribute("unit");    //单位
                        grid.Rows[rownum].Cells[5].Value = xe.GetAttribute("type");    //数据类型
                        //     grid.Rows[rownum].Cells[6].Value = xe.GetAttribute("scope");//范围
                        grid.Rows[rownum].Cells[6].Value = xe.GetAttribute("desc");    //说明

                        NodeNamePathBuffer[rownum] = NodeNamePathBuffer[item.RowIndex] + "/" + xe.Name;
                        rownum++;
                        ShowNodes(xn, cell[i]);
                        break;

                    case XmlNodeType.Text:
                        //text 在上一行中显示值即可
                        rownum--;
                        grid.Rows[rownum].Cells[2].Value = xn.Value;
                        rownum++;
                        break;
                    }

                    i++;
                }
            }
            else
            {
                return;
            }
        }
Example #3
0
 public DataGridViewGroupColumn()
 {
     CellTemplate = new DataGridViewGroupCell();
     ReadOnly     = true;
 }
Example #4
0
 /// <summary>
 /// 添加子结点
 /// </summary>
 /// <param name="cell"></param>
 /// <returns></returns>
 public int AddChildCell(DataGridViewGroupCell cell)
 {
     return(AddChildCellRange(new DataGridViewGroupCell[] { cell }));
 }
Example #5
0
        private void AddItems(string path)
        {
            //      XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(path);

            root = xmlDoc.DocumentElement;
            //初始化行,计算节点总数
            int rootnum = 1;

            rootnum += CountNodeNum(root);
            for (int i = 0; i < rootnum; i++)
            {
                grid.Rows.Add();
            }
            //初始化节点路径存储数组
            NodeNamePathBuffer = new string[rootnum];
            rownum             = 0;

            //此段代码为显示根节点------------------------------------------------------------------
            //显示第一个节点
            //node = grid.Rows[rownum].Cells[0] as DataGridViewGroupCell;
            //XmlElement xe = (XmlElement)root;
            ////设置属性值
            //xe.SetAttribute("RowNum", Convert.ToString(rownum));
            ////grid.Rows[rownum].Cells[0].Value = xe.Name + xe.GetAttribute("RowNum");
            //grid.Rows[rownum].Cells[0].Value = xe.Name;
            //NodeNamePathBuffer[rownum] = "/" + root.Name;
            //rownum++;
            ////各节点扩展显示
            //ShowNodes(root, node);
            //-------------------------------------------------------------------------------------------------------------------



            ///此段代码为不显示根节点------------------------------------------------------------------
            //指定一个节点
            XmlNode r = xmlDoc.SelectSingleNode("Root");
            //XmlElement xer = (XmlElement)r;
            //  XmlNodeList xnf = r.ChildNodes;

            XmlNodeList xnf = root.ChildNodes;

            DataGridViewGroupCell[] cell = new DataGridViewGroupCell[xnf.Count];
            int j = 0;

            foreach (XmlNode xn in xnf)
            {
                switch (xn.NodeType)
                {
                case XmlNodeType.Element:
                    XmlElement xe = (XmlElement)xn;
                    //设置属性值
                    xe.SetAttribute("RowNum", Convert.ToString(rownum));
                    cell[j] = grid.Rows[rownum].Cells[0] as DataGridViewGroupCell;
                    grid.Rows[rownum].Cells[0].Value = xe.Name;
                    //   grid.Rows[rownum].Cells[0].Value = xe.GetAttribute("name");
                    grid.Rows[rownum].Cells[1].Value = xe.GetAttribute("name");
                    grid.Rows[rownum].Cells[2].Value = xe.Value;
                    grid.Rows[rownum].Cells[3].Value = xe.GetAttribute("width");       //字节
                    grid.Rows[rownum].Cells[4].Value = xe.GetAttribute("unit");        //单位
                    grid.Rows[rownum].Cells[5].Value = xe.GetAttribute("type");        //数据类型
                    //      grid.Rows[rownum].Cells[6].Value = xe.GetAttribute("scope");//范围
                    grid.Rows[rownum].Cells[6].Value = xe.GetAttribute("desc");        //说明

                    NodeNamePathBuffer[rownum] = "/" + root.Name + "/" + xe.Name;
                    rownum++;
                    ShowNodes(xn, cell[j]);
                    break;

                case XmlNodeType.Text:
                    //text 在上一行中显示值即可
                    rownum--;
                    grid.Rows[rownum].Cells[2].Value = xn.Value;
                    rownum++;
                    break;
                }
                j++;
            }
        }