Subitems are not all added to a list view in C# using XmlNodeList
Posted
by
tim
on Stack Overflow
See other posts from Stack Overflow
or by tim
Published on 2011-01-09T19:52:13Z
Indexed on
2011/01/09
19:53 UTC
Read the original article
Hit count: 185
I'm working on extracting data from an RSS feed. In my listview (rowNews), I've got two columns: Title and URL. When the button is clicked, all of the titles of the articles are showing up in the title column, but only one URL is added to the URL column. I switched them around so that the URLs would be added to the first column and all of the correct URLs appeared... leading me to think this is a problem with my listview source (it's my first time working with subitems). Here's the original, before I started experimenting with the order:
private void button1_Click(object sender, EventArgs e)
{
XmlTextReader rssReader = new XmlTextReader(txtUrl.Text);
XmlDocument rssDoc = new XmlDocument();
rssDoc.Load(rssReader);
XmlNodeList titleList = rssDoc.GetElementsByTagName("title");
XmlNodeList urlList = rssDoc.GetElementsByTagName("link");
ListViewItem lvi = new ListViewItem();
for (int i = 0; i < titleList.Count; i++)
{
rowNews.Items.Add(titleList[i].InnerXml);
}
for (int i = 0; i < urlList.Count; i++)
{
lvi.SubItems.Add(urlList[i].InnerXml);
}
rowNews.Items.Add(lvi);
}
© Stack Overflow or respective owner