I have a XML that stores multiple Transactions. Now i want to parse that into a ListView and return the ListView.
And here is the function that Parses the XML and returns the ListView
public ListView ReadPaths()
{
try
{
ListView oList = new ListView();
XmlDocument oXMLDoc = new XmlDocument();
oXMLDoc.Load("Buchungen.xml");
XmlNodeList oTransactions = oXMLDoc.SelectNodes("Buchungen/Buchung");
foreach(XmlNode oTransaction in oTransactions)
{
ListViewItem oItem = new ListViewItem();
if (oTransaction.Attributes["positive"].Value == "true")
oItem.ImageIndex = 0;
else
oItem.ImageIndex = 1;
oItem.SubItems.Add(oTransaction.Attributes["description"].Value);
oItem.SubItems.Add(oTransaction.Attributes["date"].Value);
oItem.SubItems.Add(oTransaction.Attributes["amount"].Value);
oList.Items.Add(oItem);
}
return oList;
}
catch(Exception ex)
{
MessageBox.Show("Fehler beim lesen der Daten: " + ex.Message, "Fehler!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
}
The ListView that I assign this source to, has a count that is greater than zero - which is expected.
XMLHandler oXMLHandler = new XMLHandler();
lstGeldEintraege = oXMLHandler.ReadPaths();
lstGeldEintraege.Refresh();
After ^this call, my ListView won´t do anything. If I try to add an Element to that ListView afterwards, it won´t react. The ListView.Items.Count is still +1 as expected but i am not able to review values of the subItems for some Reason. It also deserializes the Items that I add, but it never displays one. If i delete the ReadPaths() call, my Items show up properly. Whats that behaviour about and what could help fixing it?
No comments:
Post a Comment