Question

After a couple of hours I was finally able to get user details from xml file, but I have no idea how to filter using ComboBox or TextBox. I have been searching for samples on the internet, but what I found is very complicated. Can you give me a clue What is the easiest way to do that?

The XML File

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

This is my code so far

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);
   }
}
Was it helpful?

Solution

This Snippet may help you. 1st loop xml node while adding into the ListView, so more easy

Updated:

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
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top