我可以同时从两个数据集进行查找吗?
在 这个问题中,我询问了有关破坏数据集的问题分成子集,并得到了良好的反响。 现在我遇到了相反的问题。 我有两个不同的数据集,代表共同祖先的两个不同子类的对象,并且我需要使用相同的 TDBLookupComboBox 使用父级中存在的两个属性(ID # 和 Name)同时搜索这两个数据集班级。
查找字段允许您从多个源字段查找内容,但只能在同一数据集中查找,而不是在两个不同的数据集中查找。 查找控件仅允许您指定一个查找字段进行搜索。 有谁知道如何从两个数据集中获取数据并一起出现在组合框中?
In this question, I asked about breaking a dataset into subsets, and got a good response. Now I have the opposite problem. I've got two different datasets, representing objects of two different subclasses of a common ancestor, and I need to have the same TDBLookupComboBox search both of them at the same time, using two properties, ID # and Name, that exist in the parent class.
A lookup field allows you to look things up from multiple source fields, but only in the same dataset, not two different ones. And a lookup control only allows you to specify one lookup field to search. Does anyone know how I could get data from both datasets to appear together in the combo box?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
创建您自己的采用多个数据源的 TDBLookupComboBox。 。 。 。 我之前创建过数据库感知控件(特别是下拉组合框)。 它们非常容易做到,并为您提供所需的所有控制。
Create your own TDBLookupComboBox that takes multiple data sources. . . . I've created DB aware controls before (specifically drop down combo boxes). They are pretty easy to do and give you all the control you need.
您可以将两个数据集中的记录克隆到包含两者并集的新数据集中。
You could clone the records from both data sets into a new dataset that contains the union of both.
答案就在您链接到的原始问题中。 您说两个数据集的成员有一个共同的祖先。 因此,将所有这些对象记录放入单个 TClientDataset 中,然后对于两个后代数据集,让它们使用来自该基础数据集的克隆游标。 因此,您可以将它们作为不同的集合或作为它们的组合集合来访问。
当然,问题在于添加到后代类中的任何数据,这些数据不与基类共享(假设您有任何数据)。 。 。
The answer is in your original question you linked to. You say the members of both datasets have a common ancestor. So put all those object records into on single TClientDataset, and then for your two descendant datasets just have them use a cloned cursor from that base dataset. So you can access them as to distinct sets, or as their one combined set.
Of course the rub comes in any data that is added in the descended classes that isn't shared the base class, assuming you have any. . .
创建一个 TDataSource 或 TDataSet 后代,它实际上是其他 TDataSet 的联合。 然后,在插入时,您要么始终插入到一个特定的 TDataSet,要么根据特定字段的值确定要插入到哪个 TDataSet 的规则。 。 。 。
Create a TDataSource or a TDataSet descendant that is actually a union of other TDataSets. Then on insert you either always insert into one specific TDataSet, or have rules based on the value of a certain field that determines which TDataSet to insert into. . . .