Given
var selectedItems = listBoxControl1.SelectedItems;
var selectedItemsList = (from i in selectedItems
select i).ToList();
I receive Error
Could not find an implementation of the query pattern for source type
'DevExpress.XtraEditors.BaseListBoxControl.SelectedItemCollection'.
'Select' not found. Consider explicitly specifying the type of the
range variable 'i'.
using system.LINQ
Done
I can use foreach so it must implement IEnumerable
. I prefer to use LINQ over foreach to gather each string, if possible.
I want to take the ToString()
values for each SelectedItem in the list box control and stick them in a List<string>
. How can I do it?
Best Answer
That's not actually true, but it's irrelevant here. It does implement
IEnumerable
, but notIEnumerable<T>
which is what LINQ works over.What's actually in the list? If it's already strings, you could use:
Or if it's "any objects" and you want to call
ToString
you can use:Note that the call to
Cast
is why the error message suggested using an explicitly typed range variable - a query expression starting withfrom Foo foo in bar
will be converted tobar.Cast<Foo>()...