The following code can be used in the
Click
event of a
Button
, to find if any of the items in
CheckedListBox
is available in the
ListBox
. If available then the boolean flag
notFound
is set to
false
.
bool notFound = true;
checkedListBox1.Items.Cast<string>().Select (s => {
if (listBox1.Items.Cast<string>().Any (ls => ls.Equals(s, StringComparison.InvariantCultureIgnoreCase)))
notFound = false;
return s; });
if (notFound)
MessageBox.Show("Not found");
Alternatively,
Any
extension method can be used as follows:
if (!checkedListBox1.Items.Cast<string>().Any (s =>
(listBox1.Items.Cast<string>().Any (ls => ls.Equals(s, StringComparison.InvariantCultureIgnoreCase)))))
MessageBox.Show("Not found");