I am using linq to search product in ObservableCollection, but it does not return any result, for example I have a product name “stack”, but when I search “s”, it return no result:
private ObservableCollection<Product> _ProductList = new ObservableCollection<Product>();
public ObservableCollection<Product> ProductList
{ get { return _ProductList; } set { _ProductList = value; } }
I have a textbox, when user type, linq will search product name in the ObservableCollection:
private void productSearch_KeyUp(object sender, KeyEventArgs e)
{
// Search text
string productSearchText = productSearch.Text.Trim();
// Search product, return no result
var search = ProductList.Where(s => s.Name.StartsWith(ProductSearchText));
search.ToList().ForEach(ProductList.Add);
}
Edited:
I notice it is because of letter case problem. I needs to be in uppercase, if the product name is in uppercase, how can I search regarding of letter case?
if the problem is in the case sensetivity you may try to use this
or you can try this as well
and you probable want to use search foreach like this