我在listbox中有些选项,这些选项是数据表的某个字段对应的值,当点击某个选项时,想要在edit上显示出与这个值在同一行的其他字段的值,不知该如何做到?listbox.selected[i]之后
如何编程选择了数据表中某一行某个值后,此行其他项一一在edit上显示出来

解决方案 »

  1.   

    可以用 ListView,这样便于把数据库的信息存入每个 ListItem.Data 域里。

      TMyRec=record
        id: integer;
        name: string;
        ...
      end;
      PMyRec=^TMyRec;增加一个项。
    var
      newItem: TListItem;
      lpMyRec: PMyRec;
    begin
      new(lpMyRec);
      lpMyRec^.id := 1;
      lpMyRec^.Name := 'abc';
      newItem := ListView.Items.Add;
      newItem.Caption := lpMyRec^.Name;
      newItem.Data := lpMyRec;
    end;获取一个项edtId.Text := IntToStr(PMyRec(ListView.Items[i].Data)^.Id);
    edtname.Text := PMyRec(ListView.Items[i].Data)^.Name;
    ...
      

  2.   

    将主键写到LISTBOX里,然后根据该值从数据库里读出来,显示在EDIT上
      

  3.   


    type
      TMyRec=record
        id: integer;
        name: string;
      end;
      PMyRec=^TMyRec;var
      lpMyRec: PMyRec;procedure TForm1.AddDataToList(Lst: TListBox;Qry:TADOQuery);begin
      with qry do
      begin
        Close;
        Sql.Clear;
        Sql.Text:='';
        Open;
      end;
      while not Qry.eof do
      begin
        New(lpMyRec);
        lpMyRec.id:=X;
        lpMyRec.name:='XXX';
        Lst.AddItem('XXX',Pointer(lpMyRec));
      end;
    end;
    //在释放List时一定要用
    for I:=0 to Listbox1.items.count-1 do
    begin
      Dispose(Listbox1.Items[I]);
    end;
      

  4.   

    type
      TMyRec=record
        id: integer;
        name: string;
      end;
      PMyRec=^TMyRec;var
      lpMyRec: PMyRec;procedure TForm1.AddDataToList(Lst: TListBox;Qry:TADOQuery);begin
      with qry do
      begin
        Close;
        Sql.Clear;
        Sql.Text:='';
        Open;
      end;
      while not Qry.eof do
      begin
        New(lpMyRec);
        lpMyRec.id:=X;
        lpMyRec.name:='XXX';
        Lst.AddItem('XXX',Pointer(lpMyRec));
      end;
    end;
    //在释放List时一定要用
    for I:=0 to Listbox1.items.count-1 do
    begin
      Dispose(Listbox1.Items[I]);
    end;
      

  5.   

    我自己弄出来了,不过不是用的你的方法,我刚学delphi不久,说实话,你的方法我看不懂。但是还是非常感谢你!
      

  6.   


    用listview我能做出来,但为了界面美观简单,我要用combobx和listbox。
    谢谢你!
      

  7.   


    用listview我能做出来,但为了界面美观简单,我要用combobx和listbox。
    谢谢你!