xml listview

            this.listView1.View = View.Details;
            this.listView1.Scrollable = true;
            this.listView1.MultiSelect = false;
            this.listView1.HeaderStyle = ColumnHeaderStyle.Nonclickable;
            this.listView1.Columns.Add("Changebefore", 60, HorizontalAlignment.Right);
            this.listView1.Columns.Add("Changeafter", 100, HorizontalAlignment.Left);
            this.listView1.Visible = true;

            //From here, we should read the information from changeinfodatase.xml"
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load("changeinfodataset.xml");
            XmlNodeList nodeList = xmlDoc.SelectSingleNode("changeinfo").ChildNodes;//获取changeinfo节点的所有子节点
            foreach (XmlNode xn in nodeList)//遍历所有子节点   获取items节点
            {
                XmlElement xe = (XmlElement)xn;//将子节点items类型转换为XmlElement类型  
                XmlNodeList nls = xe.ChildNodes;//继续获取items  xe子节点的所有子节点  
                ListViewItem lv = new ListViewItem();
                foreach (XmlNode xn1 in nls)//遍历  
                {                 
                    XmlElement xe2 = (XmlElement)xn1;//转换类型  
                    if (xe2.Name == "changebefore")//如果找到  
                    {
                        //From here, we get the information "changebefore"               
                        lv.SubItems[0].Text = xe2.InnerText;
                    }
                    if (xe2.Name == "changeafter")
                    {
                        //From here, we get the informatio "changeafter"
                        lv.SubItems.Add(xe2.InnerText);
                    }                  
                }
                this.listView1.Items.Add(lv);
            }

posted @ 2010-01-02 12:36  greencolor  阅读(356)  评论(1编辑  收藏  举报