I have created a Search button and an associated texbox in Windows Forms to search through a DataGridView. The DGV shows information in a BindingList. The BindingList has the properties PartID, Name, Price, Instock, Min and Max which are of the types int, string, decimal, int, int and int. I can get the search to function properly but the code itself looks clunky. How can I make my 'for' loop search through the BindingList with less code?
for (int i = 0; i < Inventory.AllParts.Count; i++)
{
//I would like to condense this if statement into one line of code
if (Inventory.AllParts[i].PartID.ToString().Contains(partsSearchTextBox.Text.ToString())
|| Inventory.AllParts[i].Name.ToString().Contains(partsSearchTextBox.Text.ToString())
|| Inventory.AllParts[i].Price.ToString().Contains(partsSearchTextBox.Text.ToString())
|| Inventory.AllParts[i].Instock.ToString().Contains(partsSearchTextBox.Text.ToString())
|| Inventory.AllParts[i].Min.ToString().Contains(partsSearchTextBox.Text.ToString())
|| Inventory.AllParts[i].Max.ToString().Contains(partsSearchTextBox.Text.ToString()))
{
dgvParts.Rows[i].Selected = true;
found = true;
}
}