c# - 使用 SearchBar 过滤 SQLite 数据库
问题描述
我已经能够生成并显示一个 SQList 数据库,现在我想用搜索栏过滤它,我已经阅读了很多教程,但我无法让它工作......
我有一个带有以下代码的 SQLite 模型:
using SQLite;
namespace AppListo
{
public class Employee
{
[PrimaryKey, AutoIncrement]
public long EmpId
{ get; set; }
[NotNull]
public string EmpName
{ get; set; }
}
}
...我从数据库中检索数据列表:
public List<Employee> GetAllEmployees()
{
return dbConn.Query<Employee>("Select * From [Employee]");
}
...我在 ContentPage 中使用此 xaml 代码显示列表:
<ListView x:Name="lstData" HasUnevenRows="false" Header="Header Value" Footer="Footer" ItemSelected="OnSelection" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal" Padding="5,5,5,5">
<Label Text="{Binding EmpName}" FontSize="Medium" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
...以及后面的代码:
var vList = App.DAUtil.GetAllEmployees();
lstData.ItemsSource = vList;
...但我不知道如何使用搜索栏过滤此列表。你能帮我实现它吗?
提前致谢
解决方案
使用 LINQ
var vList = App.DAUtil.GetAllEmployees();
lstData.ItemsSource = vList.Where(e => e.Name.Contains(mySearchString));
推荐阅读
- python - 如何使用 python 和 Tkinter 为票务桌面应用程序创建 FTP 服务器
- java - 无论程序是从控制台还是 Eclipse 启动,是否有一种干净的方法来解决文件路径问题?
- c# - 使用 PdfPig 提取的过程图像
- python - HTTP Web 服务器 POST 返回空白页(Python)
- javascript - 弹出框内容 - 弹出框内未显示按钮(JQuery / Javascript / HTML / Bootstrap)
- python - 从 Python 中的谷歌查询中检索单个值
- arrays - 如何打印 Lua 表中的所有值?
- azure - 以 5 个为一组并行启动 vm
- java - 合并排序 Java 实现,因此合并在一个数组内工作,第二个拆分数组反转
- php - 如何快速填充 php 对象的私有属性?