C
C#17mo ago
Acorn

✅ Returning (Collection) from LINQ Query

I query from a list called invItems based off a filter, but after returning the results from the query using ToList(), the items are shown as (Collection) in my combo box. Why is it doing this?
7 Replies
Angius
Angius17mo ago
Because you add filteredItems Not item
Angius
Angius17mo ago
Acorn
Acorn17mo ago
now it returns this. the filter does work, as it will show less items depending on the filter. but i want it to show the items name / description / cost
Angius
Angius17mo ago
You can either add just those strings to the list, add a .ToString() overload to your class, or maybe use some binding stuff on the UI side Not sure about the last option since I never worked with Winforms
nickproud
nickproud17mo ago
How do you want it to look? If you want each item to read name / description / cost, then when you do your foreach to add the list items, instead of adding the invitem object, put those three properties together using string interpolation.
Servator
Servator17mo ago
I would use DisplayMember
Acorn
Acorn17mo ago
this worked, thank you so much... im still new to C and sometimes struggle to think like the computer does. thank you and thank you everyone for the help