Referencing subitems in a ListView Question

N

needin4mation

Please consider this code:

XmlTextReader reader = new XmlTextReader("FileList.xml");
ListViewItem lvi = new ListViewItem();
try
{
lisInfoList.Items.Add("Starting XML file read...");
while (reader.Read())
{

switch(reader.NodeType)
{
case XmlNodeType.Element:
string name = reader.Name;
if (name == "source")
{
lvi = new ListViewItem(reader.ReadInnerXml());
listViewFiles.Items.Add(lvi);
}
if (name == "destination")
{
lvi.SubItems.Add(reader.ReadInnerXml());
lvi.SubItems.Add("Ready...");
}
break;
}

}
lisInfoList.Items.Add("End XML file read...");
lisInfoList.Items.Add("Ready to copy...");
foreach (ListViewItem item in listViewFiles.Items)
{
lvi.SubItems[2].Text="hello";
}
}
catch (XmlException exc)
{
lisInfoList.Items.Add("Error: " + exc.Message + ", " +
exc.LineNumber);
}

I am thinking that I should have used a listbox for this, but, what I
am trying to do is manually update the [2] subitem (it is titled
"Result"). What I will end up doing is iterating through each item and
subitem for the source and destination and then after I do what I need,
I manually update the "Result..." as I am doing it

What happens is that "hello" is only put on the last item, so I have:
source destination result
c:\first_file c:\dest ready...
c:\second_file c:\dest hello

I want both results to say "hello." Thanks for any help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top