在DBGrid搜索关键词并定位的问题(50分)

  • 主题发起人 龙啸九天
  • 开始时间

龙啸九天

Unregistered / Unconfirmed
GUEST, unregistred user!
在Edit1里输入一个关键词,按“搜索”按钮,程序将在DBgrid的数据里搜索含有
关键词的行,然后定位在该行,再按F3键,则继续搜索并定位,这样的程序怎样
实现?
 
这与dbgrid无关,是dbgrid.datasource.dataset有关。
 
adodataset.locate
 
edit1.onchange中
table1.Locate(Field1, edit1.Text,[loCaseInsensitive, loPartialKey]);
 
我没有用到
table1.Locate(Field1, edit1.Text,[loCaseInsensitive, loPartialKey]);
的table

直接是DBgrid挂在dataset上
 
dateset还不是一样
 
可以定位了,但有发现新的问题

现在只能匹配字段的开头字符,比如搜索“中国”只能找到“中国队”

而“在中国旅游”就搜索不到

怎样解决?
 
with Table1 do

begin
EditKey;
FieldByName('State').AsString := 'CA';
FieldByName('City').AsString := 'Santa Barbara';
GotoKey;

end;
 
假如你DBGrid中的数据是Query查询出来的。或是Table中的数据是很好办的。

if query1.eof then exit;
while not query1.eof do
begin
if query1.fieldbyname('name').asstring<>edit1.text then
query1.next
else
break;

如果是Table中的数据也是一样的。
按F3时执行这个过程就可以了,前提是qurey或table已经OPEN
 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
987
SUNSTONE的Delphi笔记
S
S
回复
0
查看
805
SUNSTONE的Delphi笔记
S
顶部