I recently databounded an xml file to a listbox. Now I want to write some function to add or delete items from that listbox. The following error came up while trying listbox.items.add or listbox.items.insert:
Access and modify elements with ItemsControl.ItemsSource instead.
I googled this and it said to work on the ‘model’ instead,
However I have no clue how to do that. So how can I add or delete items to and from the datasource? I would hate having to add xml elements and values to the original and then update the file as the data source…
How about loading the XML into a dataset and then manipulating the dataset and rebinding?
Instead of using the XML file and binding that to the listbox, try this: (source)
Lets assume you XML is rather simple. To add a tow to the DataSet you would do: (source)
Here is an XML example that should work with the above:
I have not compiled or tried to run any of that, but you should get the general idea and adapt it to your code.