把XML中的Code读出来,然后加入ComboBox的Items就可以了。
读取XML文件,比较简单的方法蛇XmlTextReader.读取XML的代码:
XmlTextReader reader = null;
try
{
  reader = new XmlTextReader(filePath);
  reader.WhitespaceHandling = WhitespaceHandling.None;  while (reader.Read())
  {
     switch (reader.NodeType)
     {
       case XmlNodeType.Element:
       {
          // 这里reader.Name 就是Node的名称
        }
       break;
default:
break;
}
}
}

解决方案 »

  1.   

    问题已解决,谢谢大家的帮忙.
    我使用DATASET方法
      

  2.   

    OK我來貼﹗  
     DataSet xmlread = new DataSet();
                xmlread.ReadXml("XMLFile1.xml");
                comboBox1.DataSource = xmlread.Tables[0];
                comboBox1.DisplayMember = "name";
                comboBox1.ValueMember = "age";
      

  3.   

    <?xml version="1.0" encoding="utf-8" ?>
    <persons>
      <person>
        <name>zhangsan</name>
        <age>10</age>
      </person>
    </persons>
    又遇到点新问题,我利用combox来是实现有选择性加密XML文档节点.代码如下
      DataSet ds = new DataSet("test");
         ds.ReadXml(filePath);
         DataTable dt = ds.Tables["person"];
             foreach (DataRow rowNameList in dt.Rows)
             {
              comboBox1.Items.Add(rowNameList["name"].ToString());
              comboBox1.Items.Add(rowNameList["age"].ToString());
             }
    在C#winform下,XML语法里怎么调用combox所选择的值
    string friendName = comboBox1.Text.Trim();?????XML选择节点的加密方法,我只知道这两种:
    XmlElement xmlElemt = xmlDoc.SelectSingleNode("name") as XmlElement;
    XmlElement xmlElemt = xmlDoc.GetElementsByTagName("name")[0] as XmlElement;
      

  4.   

    你沒有綁定ValueMember 值﹐所以你不能用comboBox1.SelectedValue來選擇得值﹐選到的都是null,你上面只是把text的值添加進去﹐所以只能這樣選擇comboBox1.Text.Trim();
    用我上面給你貼出來的代碼就可以選擇comboBox1.SelectedValue即我上面那樣的對應的age的值。
      

  5.   

    我想在combox里显示的是所有节点的值,可供选择.....
    然后再把所选择的节点值传递到加密类里.
      

  6.   

    comboBox1.SelectedValue這樣就是選擇到了你所選擇的值了呀﹐
      

  7.   

    DataSet xmlread = new DataSet();
                xmlread.ReadXml("XMLFile1.xml");
                comboBox1.DataSource = xmlread.Tables[0];
                comboBox1.DisplayMember = "name";
                comboBox1.ValueMember = "age";這樣在comboBox1中顯示的是﹕zhangsan
                               lisi
    當你選擇﹕zhangsan
         用comboBox1.SelectedValue取得的值就是:10
           即﹕string str=comboBox1.SelectedValue.ToString().Trim();這里的str就是:10
      

  8.   

    我想获得的是节点而不是节点的值:比如我想要的是name节点,而不是name节点的值zhangsan,然后加密类再根据所选择的节点进行动态加密