BindingSource 和 DataGridView
我有两个 DataGridView 通过 BindingSources 和 TableAdapters 绑定到底层数据源。
我有两个模型; 字符串和表格。 表格 -> [id、句柄、描述] 字符串 -> [id, handle, table_id]
所以表和字符串之间存在多对一关系。
选择“表”DataGridView 来过滤“字符串”DataGridView 的内容的最简单方法是什么?
我知道“字符串”DataGridView 的数据源可以设置为“表”DataGridView 的绑定源,但这不支持多重选择。
目前,当“表”DataGridView 上的选择发生更改时,我正在迭代所选行并为“字符串”DataGridView 构建基于字符串的过滤器,但我发现这又慢又乱。
有人知道更好的方法吗?
I have two DataGridView's bound to an underlying DataSource through BindingSources and TableAdapaters.
I have two models; strings and tables.
Tables -> [id, handle, description]
Strings -> [id, handle, table_id]
So there's a many-to-one between Tables and Strings.
What's the easiest way to make the selection of the "tables" DataGridView to filter the contents of the "strings" DataGridView?
I understand the datasource of the "strings" DataGridView can be set to the bindingsource of the "tables" DataGridView but this does not support multiple selection.
At the moment, when the selection on the "tables" DataGridView is changed, I am iterating over the selected rows and building a string-based filter for the "strings" DataGridView but I find this slow and messy.
Anyone know a nicer way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的代码可能存在其他一些问题,导致速度变慢。
由于它很混乱,我通常只是将代码移动到 DataGridView 上的扩展方法中,以便我可以轻松地获取元素列表。 内置/简单用于单选。
You might have some other issue with the code that is making it slow.
About it being messy, I usually just move code that lets me easily grab lists of elements to extension methods over the DataGridView. Built-in/simple is for single selection.
您可以为每个表使用两个不同的 BindingSource。 或者,您可以仅使用数据填充第一个表,而根本不使用 BindingSource。 然后,您可以对 DataGridView 中的 SelectionChanged 事件做出反应,以在表 2 上的 BindingSource 上设置筛选器。
有很多方法:您自己能够找出新方法吗?
You can just use two different BindingSources for each of the tables. Or you can fill the first table with just the data, without using a BindingSource at all. Then you can react on the SelectionChanged event from the DataGridView to set the filter on the BindingSource on table 2.
There's lots of ways: are you able of figuring out new ways yourself?