I assume your user will enter Name=aa or ItemCode=bb etc in that format. In that case you would need to split the entry into it's 2 parts using something like this:-
string[] searchArray = txtNameSearch.Text.Split(new char[] { '=' });
you could then use a switch statement to call a method that takes a Predicate<> as a parameter and pass in a lambda expression when you call it, something like this:-
private void Filter(Predicate<myClass> filter)
{
List<myClass> filteredClassList = (from myclass in myClassList where filter(myclass) select myclass).ToList();
dgMyClass.DataContext = filteredClassList;
}
switch (searchArray[0])
{
case "Name":
Filter(myclass => myclass.Name.Contains(searchArray[1]) == true);
break;
case "ItemCode":
Filter(myclass => myclass.ItemCode.Contains(searchArray[1]) == true);
break;
}
I used a WPF form and DataGrid to test this but it would be the same for a WinForms project, just change DataContext to DataSource
Hope this helps