listview findCaption

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;

posted @ 2019-06-27 08:48  绿水青山777  阅读(382)  评论(0编辑  收藏  举报