listview findCaption

本文详细介绍了在Delphi中如何使用键盘事件处理程序来搜索列表视图中的项目。通过监听Enter键,代码实现了查找并高亮显示匹配项的功能,提高了用户交互效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

procedure TfrmCaoZYGLNew.edt1KeyPress(Sender: TObject; var Key: Char);
var
AItem: TListItem;
i: Integer;
isFound: Boolean;
begin
if key = #13 then
begin

AItem := ListView1.FindCaption(nFount, Trim(edt1.Text), True, False, true);

if not Assigned(AItem) then
begin
isFound := False;
for i := 0 to ListView1.Items.Count - 1 do
begin
if Trim(edt1.Text) = ListView1.Items.Item[i].SubItems[0] then
begin
nFount := 0;
isFound := True;
ListView1.Selected := ListView1.Items[i];
ListView1.Items[i].MakeVisible(True); //定位后显示出来
Break;
end
else if (i = ListView1.Items.Count - 1) and not isFound then
begin
MSGWarning('没有找到该操作员');
nFount := 0;
Break;
end;
end;
end
else
begin
ListView1.Selected := AItem;
AItem.MakeVisible(True); //定位后显示出来
if ListView1.Selected.Caption = Trim(edt1.Text) then
nFount := 0
else
nFount := ListView1.Selected.Index;
end;

ListView1.SetFocus;
end;
end;

转载于:https://www.cnblogs.com/maweiwei/p/11094964.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值