Bassicly i can load my xml file correctly into a listview but i then want the user to be able to click on the items in the listview and from their display information about that item thats not in the listview but the xml.
So i thought i could load up an xml when the user clicks on the item and somehow fetch that information but it does not display anything on the label. Any help would be appreciated thanx.
XML:
<?xml version = "1.0" encoding="utf-8"?>
<project>
<test>
<code>ss</code>
<name>test</name>
</test>
<test>
<code>ss1</code>
<name>test1</name>
</test>
</project>
code:
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
namespace form
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
XmlTextReader reader = new XmlTextReader("XMLfile1.xml");
XmlNodeType type;
while (reader.Read())
{
type = reader.NodeType;
if (type == XmlNodeType.Element)
{
if (reader.Name == "name")
{
reader.Read();
listView1.Items.Add(reader.Value);
}
}
}
reader.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
XmlTextReader reader = new XmlTextReader("XMLFile1.xml");
XmlNodeType type;
while (reader.Read())
{
type = reader.NodeType;
if (type == XmlNodeType.Element)
{
if (reader.Name == "test")
{
reader.Read();
codelabel.Text = "s";
}
}
}
}
private void groupBox2_Enter(object sender, EventArgs e)
{
}
}
}