Question

What I am trying to do is pass a list of items to a method rather than the item itself.

Was it helpful?

Solution

Well, everything can be boxed to 'Object' and they may share a hierarchical parent closer (I don't have the docs in front of me, and I don't think it's important enough to this discussion to check).

I'm wondering exactly what you're attempting to accomplish. If you have a ComboBox and a ListBox which both contain the same kind of objects (let's just call them strings, for now, but it should apply to anything you want, I'd think), you can, with relative ease, extract the object from the ListBoxItem or from theComboBoxItem and then pass around List<string> or IEnumberable<string> or whatever.

If they are not the same object type, for whatever reason, you may need to check what you're doing and why- the likelihood of needing to combine a two lists of two completely different objects and pass the resultant concatenated list around is fairly slim.

OTHER TIPS

If your list box items are of type Car a collection of them can always be cast to IEnumerable<Car>. If you take in an IEnumerable<Car> to as parameter to the method you can loop through the items with foreach or apply linq methods to it. If you want to be able to modify the collection's content you will have to be a bit more specific and e.g. use an IList<Car>.

ListItemCollection YourList = YourDropDownList.Items;

In System.Windows.Controls a ComboBoxItem is a ListBoxItem.

Of course, everything is an object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top