If I understand what you're aslking...
Since the
ListBoxItems
collection is a collection of type
object
, you don't have to cast the object when you add it to the
ListBox
. Just add this method to your item class:
public override string ToString()
{
return desiredProperty;
}
Now, you can simply add your items to the listbox, and the listbox will use whatever is returned by
ToString()
for displaying the items.
When you use ListBox.SelectedItem, you will need to cast that to the appropriate type (in your case,
TorpedoSvcProvider
I suspect:
TorpedoSvcProvider selected = listBox1.SelectedItem as TorpedoSvcProvider;