There are many ways to do that, this simple and beautiful way will do the trick for you:
String:
yourDataGridViewComboBoxColumn.Items.Cast<string>().Contains("your string value")
Long:
yourDataGridViewComboBoxColumn.Items.Cast<long>().Contains(yourLongValue)
Complex Object:
If Items
in your combo box column are complex, you should do it ths way:
yourDataGridViewComboBoxColumn.Items.Cast<YourComplexType>()
.Select(x => x.YourValueMemberField)
.Contains(yourLongValue);
For example if items are of type Category
and category has Id
and Name
and you used its Id
as ValueMember
, you can use code like this:
int value=10;
yourDataGridViewComboBoxColumn.Items.Cast<Category>()
.Select(x => x.Id)
.Contains(value);
The key point here is using Cast<T>
that helps you to cast all items to desired type.
This way you can even search in items using Where()
after Cast<T>()