c# - 用于 DataGridView (Windows.Forms) 和过滤的数组、列表或数据表
问题描述
我正在从几个源(csv 文件,..)数据读取到数组,然后通过 foreach() { .Add(..) } 读取到 DatagridView。
现在我希望有可能通过用户的文本字段输入来搜索控件中的数据。
GenericList<T>
这可能是我在 C# 中制作 DataTable 而不是数组或此类的最佳方式吗?
解决方案
您可以使用数据表
DataTable table = new DataTable();
BindingSource bs = new BindingSource();
使用 BindingSource 绑定数据表
dataGridView1.DataSource = bs;
bs.DataSource = table;
过滤记录
bs.Filter= string.Format("column LIKE '%{0}%'", value);
为什么不列出?
列表未实现IBindingList
,因此网格不知道您的新项目。
为什么不绑定列表?
您不能使用Filter
属性来过滤BindingSource
它的 DataSource 设置为BindingList<T>
.
如何使用自定义对象?
您可以创建一个扩展BiningList<>
(请参阅此)。
推荐阅读
- precision - 电报中的大数字导致精度丢失
- node.js - 使 TypeORM Redis 缓存失效
- php - Nginx 和 php 构建的 Docker 执行程序失败
- java - Intellij Idea 无法解析构造函数
- react-native - 如何使用 React-native 根据距离制作过滤器
- javascript - Javascript clone() 不是函数错误
- flutter - 什么是 _TypeError 以及如何处理/测试它?
- python - 使用 Python 子进程模块向 cmd 提示符发送命令
- ios - Firebase Crashlytics:上传 dSYM 脚本会阻止 iOS 应用构建和归档
- javascript - Spotify API 客户端凭据流返回 400 错误