Or something like this:
foreach (object item in listbox.SelectedItems)
{
}
In my case, I'd put a property into the "item" object that returns an XML representation of the object, and pass that to the database. That way, the loop shown above would look something like this:
XElement root = new XElement("root");
foreach (object item in listbox.SelectedItems)
{
XElement node = (item as MyItemType).AsXElement;
root.Add(node);
}
See how clean and tidy that is?