高分请教 delphi中listview问题

qwepoi 2002-08-02 02:33:33
listview有两列,结构如下
编号 部门
123 部门1
7374 部门2
1743 部门3
.... .....
在Edit1中输入7374,在Edit2中如何自动显示相应部门2,
在Edit1中输入1743,在Edit2中如何自动显示相应部门3,
......
......
...全文
55 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
qybao 2002-08-02
  • 打赏
  • 举报
回复
在Edit1的keypress事件里添加
var
bh,bm: string;
found: boolean;
loop: integer;
begin
if (key=#13) then
begin
bh := trim(edit1.text);
found := false;
if length(bh)=0 then
begin
ShowMessage('输入无效');
Exit;
end;
for loop := 0 to ListView1.Items.Count-1 do
begin
if ListView1.Items.Item[loop].Caption = bh then
begin
found := true;
bm := ListView1.Items.Item[loop].SubItems.Strings[0];
break;
end;
end;
if not found then
begin
ShowMessage('没有对应的编号');
Exit;
end;
edit2.text := bm;
end;
end;
windofsun 2002-08-02
  • 打赏
  • 举报
回复
上面的代码在Edit1的OnExit事件中
windofsun 2002-08-02
  • 打赏
  • 举报
回复
procedure TForm1.Edit1Exit(Sender: TObject);
var
s: string;
I: Integer;
begin
s := Edit1.Text;
for I := 0 to ListView1.Items.Count - 1 do
begin
if s = ListView1.Items[I].Caption then
begin
Edit2.Text := ListView1.Items[I].SubItems[0];
Break;
end;
end;
end;
luoweicaisd 2002-08-02
  • 打赏
  • 举报
回复
if (key=#13) and (edit1.text<>'') then
begin
query1.close;
query1.sql.clear;
query1.sql.add('select 部门 from 表名 where 编号='''+edit1.text+'''');
query1.open;
if not query1.isEmpty then
edit2.text :=query1.fieldbyname('部门').asstring
else
//查不到
end;
query1.close;
hjd_cw 2002-08-02
  • 打赏
  • 举报
回复
跟listview有什么关系? :)

5,928

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧