i have listbox that reads a xml file and gives the user the ability to add items from one list box to the other. I want to somehow save all item names into a xml file when a user clicks on a specific button. But instead of printing the name it prints this "System.Windows.Forms.ListBox+ObjectCollection"
I thought i could do this.
XmlDocument doc = new XmlDocument();
doc.Load("info.xml");
XmlNode test = doc.CreateElement("Name");
test.InnerText = listBox2.Items.ToString();
doc.DocumentElement.AppendChild(test);
doc.Save("info.xml");
This will return the type of the object, not the content.
If you want to save the entire contents of every item in your ListBox, you should iterate through every item using something like:
I’d suggest using a StringBuilder to concatenate each item.