• XML与TreeView


      1。treeview代码书写

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    private void Form1_Load(object sender, EventArgs e)
    {<br>                   //代码为TreeView添加子项
        treeView1.ContextMenuStrip = contextMenuStrip1;
        TreeNode tn = new TreeNode("默认");
        
        treeView1.Nodes.Add(tn);
     
    }
     
    private void button1_Click(object sender, EventArgs e)
    {<br>                  //代码为TreeView添加子项
        string text = textBox1.Text;
        TreeNode tn = new TreeNode(text);
        TreeNode tr = treeView1.SelectedNode;
        tr.Nodes.Add(tn);
     
    }
     
    private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
    {<br>                      //删除选中项
        treeView1.SelectedNode.Remove();
    }

     2.XML基本用法

         1XML文件

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    <?xml version="1.0" encoding="utf-8" ?>
    <Computers>
       
     
    <Computer typr="222">
     
      <Name>LenovoY460</Name>
     
      <Price>5000</Price>
      <CPU>酷睿i3</CPU>
       
       
    </Computer>
     
     
      <Computer typr="2223">
     
        <Name>Dell</Name>
     
        <Price>7000</Price>
        <CPU>酷睿i7</CPU>
     
     
      </Computer>
       
       
    </Computers>
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    XmlDocument doc = new XmlDocument();
              doc.Load("XMLFile1.xml");
              XmlNode xn = doc.DocumentElement;
              foreach (XmlNode item in xn.ChildNodes) {
     
                  //foreach (XmlNode item1 in item.ChildNodes) {
     
                  //    switch (item1.Name) {
                       
                  //        case "Name":
                  //            Console.WriteLine("电脑的名字是:" + item1.InnerText);
                  //            break;
                  //        case "Price":
                  //            Console.WriteLine("电脑的价格是:" + item1.InnerText);
                  //            break;
                  //        case "CPU":
                  //              Console.WriteLine("电脑的CPU是:" + item1.InnerText);
                  //            break;
                       
                      
                       
                  //    }
                   
                   
                  //}
                  Console.WriteLine(item.Attributes["typr"].Value);
                  Console.WriteLine("电脑的名字是:" + item["Name"].InnerText);
                  Console.WriteLine("电脑的Price是:" + item["Price"].InnerText);
                  Console.WriteLine("电脑的CPU是:" + item["CPU"].InnerText);
              }
              Console.ReadKey();
  • 相关阅读:
    win7 64bit下使用PL/SQL Developer连接Oracle
    C#高级开发之 特性(Attribute)三
    K3单据表结构描述和相关关联SQL语句以及金蝶插件相关说明
    K3老单插件控制字段显示
    金蝶K3插件开发-控制单据焦点(BOS单据、工业单据)
    K3 单据,单据体自定义字段显示及时库存
    C#高级开发之反射(Reflection)二
    C#高级开发之泛型一
    python学习——协程
    python学习——线程
  • 原文地址:https://www.cnblogs.com/zfx123--/p/6599709.html
Copyright © 2020-2023  润新知