Example #1
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;
            }
        }