prabhakaran
prabhakaran

Reputation: 5274

How to get CheckedListBox.checkedItems as a stringlist

I am trying to get CheckedListBox.CheckedItems as a StringList. But I don't know how to get it. I am trying to make it as a one liner using LINQ. My insufficient experience in .Net-C# is not capable to do that. Can anybody say how to do that?

Note: I am using .Net-4.0.

Upvotes: 6

Views: 10760

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038810

If the values you stored in those items are strings:

List<string> items = chk.CheckedItems.Cast<string>().ToList();

If they are of some custom type you could use that type:

List<SomeTypeUsedForTheItems> items = chk.CheckedItems.Cast<SomeTypeUsedForTheItems>().ToList();

Upvotes: 24

Related Questions