C
C#2y 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
Angius2y ago
Because you add filteredItems Not item
Angius
Angius2y ago
Acorn
AcornOP2y 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
Angius2y 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
nickproud2y 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
Servator2y ago
I would use DisplayMember
Acorn
AcornOP2y 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
Want results from more Discord servers?
Add your server