2013-12-21 69 views
2

幾個小時後,我終於能夠從xml文件中獲取用戶詳細信息,但我不知道如何使用ComboBoxTextBox進行過濾。我一直在網上搜索樣本,但是我發現它非常複雜。你能給我一個線索什麼是最簡單的方法來做到這一點?如何閱讀xml文件的困惑

XML文件

<kisiler> 
    <kisi> 
     <no>1</no> 
     <isim>Mehmet</isim> 
     <soyisim>Duran</soyisim> 
    </kisi> 
<kisiler> 

這是到目前爲止我的代碼

private void button1_Click(object sender, EventArgs e) 
{ 

    XDocument doc = XDocument.Load(@"C:\dosya.xml"); 
    var q = from c in doc.Elements("kisiler").Elements("kisi") 
    select new 
    { 

     num = c.Element("no").Value, 
     name = c.Element("isim").Value, 
    }; 

    listView1.Columns.Add("Number", 100, HorizontalAlignment.Left); 
    listView1.Columns.Add("Name", 100, HorizontalAlignment.Left); 
    foreach (var item in q) 
    { 
     var lvi=listView1.Items.Add(item.num); 
      lvi.SubItems.Add(item.name); 
    } 
} 
+0

是它的工作,我的代碼? – Kirk

回答

0

這段代碼可以幫助你。第一環的XML節點同時加入到ListView中,因此更容易

更新時間:

XmlDocument doc = new XmlDocument(); 
doc.Load("sample.xml"); 
XmlElement root = doc.DocumentElement; 
XmlNodeList nodes = root.SelectNodes("some_node"); // You can also use XPath here 

foreach (XmlNode node in nodes) 
{ 
    listView1.Items.Add(node.Attributes["element name"].Value); 
    // or add here your listview items 
}