I'm new to delphi and have created an SQL query which displays the results of a search entered by the user through an edit box (showing data from 2 related tables) in a dbGrid. The dbgrid displays no data until a search has been made and then the results of that search are displayed, however i was wondering whether it was possible to show all the related data in the dbgrid as if it were a table and the search then simply selects from it? thanks
我是delphi的新手,并创建了一个SQL查询,该查询显示用户通过dbGrid中的编辑框(显示来自2个相关表的数据)输入的搜索结果。 dbgrid在搜索完成之前不显示任何数据,然后显示该搜索的结果,但我想知道是否可以在dbgrid中显示所有相关数据,就好像它是一个表,然后搜索只是选择从中?谢谢
1 个解决方案
#1
0
You could display all the data in the table. Then write an onExit event handler for your edit box which would look something like this (assuming that the string which you are entering in the edit box is supposed to match the value in the 'name' field of the query)
您可以显示表中的所有数据。然后为你的编辑框写一个onExit事件处理程序,看起来像这样(假设你在编辑框中输入的字符串应该与查询的'name'字段中的值匹配)
query.locate ('name', edit1.text, [loPartialValue]);
This will cause the dbgrid's cursor to jump to the first line which matches the string in the edit box.
这将导致dbgrid的光标跳转到与编辑框中的字符串匹配的第一行。
Instead of using the OnExit event, you could also use the OnChange event of the edit box, but this would mean a search after every key stroke.
您也可以使用编辑框的OnChange事件,而不是使用OnExit事件,但这意味着在每次击键后进行搜索。
Your question was a bit vague so it's difficult to give a specific answer.
你的问题有点模糊,所以很难给出一个具体的答案。
#1
0
You could display all the data in the table. Then write an onExit event handler for your edit box which would look something like this (assuming that the string which you are entering in the edit box is supposed to match the value in the 'name' field of the query)
您可以显示表中的所有数据。然后为你的编辑框写一个onExit事件处理程序,看起来像这样(假设你在编辑框中输入的字符串应该与查询的'name'字段中的值匹配)
query.locate ('name', edit1.text, [loPartialValue]);
This will cause the dbgrid's cursor to jump to the first line which matches the string in the edit box.
这将导致dbgrid的光标跳转到与编辑框中的字符串匹配的第一行。
Instead of using the OnExit event, you could also use the OnChange event of the edit box, but this would mean a search after every key stroke.
您也可以使用编辑框的OnChange事件,而不是使用OnExit事件,但这意味着在每次击键后进行搜索。
Your question was a bit vague so it's difficult to give a specific answer.
你的问题有点模糊,所以很难给出一个具体的答案。