Quote:
i written the below code.
foreach (item i in yourCollection)
{
i.IsSelected = true;
}
You clearly didn't write that code. You found some pseudo-code posted somewhere
*, and copied it to your project without bothering to understand what it's doing, or what parts you need to replace.
You need to replace
item
with the type of the items in your collection, or with the
var
keyword. You haven't told us the type name of the items in your collection, so you'll have to work that one out for yourself.
You need to replace
yourCollection
with the name of the property or field which stores your collection. At a guess, that would be either
Granularitylist
or
VendorList
- you mentioned both in your question, and it's not clear which collection you're trying to use.
Whatever type is in your collection, you'll need to make sure it has a public
IsSelected
boolean property. You'll also need to fix your
ItemContainerStyle
, which is currently targeting
ListBox
instead of
ListBoxItem
.
I suggest you go back to where you found the code, re-read the entire post, and try to understand it. Don't just randomly copy blocks of code to your project without understanding what they do!
* At a guess, you copied the code from this StackOverflow answer[^].