在组合框中列出搜索结果
我想改变我们的搜索,因为它现在有点老套。 目前它的工作原理如下:
- 用户在文本框中输入文本,例如 Volvo 并开始搜索。
- 此用 SQL 搜索所有包含沃尔沃的帖子。
- 结果是一个包含 2 列的列表:BoldID 和 DisplayValue。
- BoldID 只是在数据库中标识对象的唯一编号。
- DisplayValue 是用户在结果列表中看到的内容。
- 结果集中的每一行都用用户列表中的行号进行标识。第一个为 1,第二个为 2,依此类推。
- 还有一个限制,即通过在代码中循环查询仅按意图显示最多 99 个命中。查询返回许多命中并不好,因为在用户命中列表中包含更多命中没有任何意义。在这种情况下,搜索应该更加具体。
结果列表显示在称为右窗格的单独全局窗口中。棘手的部分是,如果从模式对话框中搜索,则右窗格必须从主窗口中脱离,以便能够使用鼠标选择一个值。我们怀疑这可能是应用程序有时通过主窗口后面的模式对话框锁定自身的原因。
更改后,它应该像这样工作:
用户在组合框中输入文本,然后像以前一样开始按需使用 SQL 进行搜索。但结果集显示在组合框中。所以我只想在可能的情况下更改显示,因为有很多旧的 SQL 查询正在使用并且现在工作正常。
我们使用 Delphi 2007、Interbase 2009 和 DevExpress 的组件。昨天我尝试将自定义数据源连接到组合框,但我意识到这尚未实现。请参阅如何在 TcxExtLookupComboBox 中使用 TcxCustomDataSource。我想使用自定义数据源来实现行号和最大点击数。上面列表中的 Se 6 和 7。
所以现在我看到两个选项:
- 使用数据库感知组合框
- 使用文本框并附加一个网格来显示结果集。
组合框更简单,因为它是一个完整的组件,但我不知道如何实现上面列表中的功能 6 和 7。 文本框+网格提供了更多自由,但需要更多工作。
我更喜欢第一个选择。目前的问题是:
- 我认为Interbase SQL无法限制结果集中的点击量。必须用代码来完成。这是如何使用数据库感知组合框来完成的?
- 如何在结果集中显示行号?
更新1: 感谢 Marjan,要求 7 已解决,谢谢。 至于6我觉得比较难。理想情况下,我希望它在 SQL 中,这样我就可以提取自己的列,例如 添加行号。但 Interbase 不支持这一点。
I want to change our search as it is a bit hacky now.
Currently it works like this:
- User enter a text in a textbox, for example Volvo and start searching.
- This search with SQL all posts containing Volvo.
- The result is a list with 2 columns, BoldID and DisplayValue.
- BoldID is just an unique number to identify the object in database.
- DisplayValue is what the user see in the list of results.
- Each row in the resultset is identified with a row number in users list. The first with 1, the second with 2 and so on.
- There is also a limitation to only show max 99 hits by intention by looping the query in code. It is not good to have a query that returns many hits as it no meaning to have more in the users hit list. The search should be more specific in that case.
The result list is displayed in a separate global window called rightpane. The hacky part is that if searching from a modal dialog then rightpane must be undocked from the main window to be able to pick a value with the mouse. We suspect this could be a reason that the application sometimes lock itself with the modal dialog behind the main window.
After change it should work like this:
The user enter text in a Combobox and start searching with SQL on demand like before. But the resultset is displayed in the combobox. So I only want to change the display if possible as there are a lot of old SQL queries that is in use and works fine now.
We use Delphi 2007, Interbase 2009 and components from DevExpress. Yesterday I tried to connect a customdatasource to a combobox, but I realize this was not implemented yet. See How to use a TcxCustomDataSource in a TcxExtLookupComboBox. I want to use a custom datasource to implement row number and max number of hits. Se 6 and 7 in the list above.
So now I see 2 options:
- Use a DB-aware combobox
- Use a textbox and attach a grid to it to display the resultset.
The combobox is simpler because it is a whole component, but I don't know how to implement feature 6 and 7 from the list above.
The textbox + grid give more freedom but require more work.
I prefer the first option. The current problems is:
- I think Interbase SQL cannot restrict the amount of hits in the resultset. It must be done with code. How is this done with a DB-aware combobox ?
- How can I display row numbers in the resultset ?
Update 1:
Requirement 7 is solved thanks to Marjan, thanks.
As for 6 I think it is harder. Ideally I want it in SQL so I could extract an own column like Adding row no. But Interbase don't support that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要求6:
假设db的id值为整数,则可以使用控件的标签或组合框/列表框中的字符串的Object来存储id值。
[伪代码]
并像这样使用它
要求 7:
使用数据库感知组合框/列表框循环查询直到 eof 或 99 行结束。所以你需要依赖 SQL。即使您不想更改任何当前的 SQL 语句,也可以使用 SQL 的“TOP”功能来限制行数。例如,
使用短语:(
在 Interbase SQL 中,您可以在 order 子句之后 请参阅 http 中的示例) ://blogs.teamb.com/craigstuntz/dtpostname/ibsqlintro/ - 几乎在页面底部)
Requirement 6:
Assuming that the db's id value is an integer, you can use the tag of a control or the Object of the strings in a combobox/listbox to store the id value.
[pseudo code]
and use it like so
Requirement 7:
Using a db aware combobox/listbox looping through the query til eof or 99 rows is out. So you would need to rely on SQL. Even if you do not want to change any of the current SQL statements, you could use SQL's "TOP" feature to limit the number of rows. For example
In Interbase SQL you can use the phrase:
just after the order clause (see example at http://blogs.teamb.com/craigstuntz/dtpostname/ibsqlintro/ - almost the bottom of the page)
Interbase 有一个 ROWS 子句,显然用于您想要的用途。
Interbase has a ROWS clause, apparently used for what you want.