Reputation: 611
I have a gridview containing files from within a folder and adding a search function. I encountered a problem while searching, that is if the file name contained a large letter, but I typed it using lowercase letters, then it can't be found. Like the picture below:
How to overcome it, so as not to care about lowercase letters and uppercase letters in search results?
Code:
ObservableCollection<Book> datasource = new ObservableCollection<Book>();
private void SearchText_TextChanged(object sender, TextChangedEventArgs e)
{
if (!string.IsNullOrWhiteSpace(searchText.Text))
{
this.itemGridView.ItemsSource = this.datasource.Where((item) => { return item.Name.Contains(searchText.Text); });
}
else
{
this.itemGridView.ItemsSource = datasource;
}
}
Book.cs:
public class Book
{
public string Name { get; set; }
public string Direktori { get; set; }
public ImageSource Image { get; set; }
}
Upvotes: 0
Views: 150
Reputation: 138
Add a StringComparison
parameter to the Contains()
method. So like this:
return item.Name.Contains(searchText.Text, StringComparison.OrdinalIgnoreCase);
Upvotes: 2