比如一个listbox1,用adoquery动态传进了几行items, 再建一个edit1,
要使鼠标点击listbox1中的某一行,使其值自动传给 edit1.text,怎么弄呢???

解决方案 »

  1.   

    自动。。 listbox1事件里写吧
      

  2.   

    在listbox的mousedown里写,应用ListBox的ItemAtPos方法。
      

  3.   

    已解决。procedure Tfrm.ListBox1Click(Sender: TObject);
    begin
       edit1.text:=ListBox1.Items.Strings[ListBox1.ItemIndex];
    end;
      

  4.   

    function GetFirstSelection(List: TCustomListBox): Integer;
    begin
      for Result := 0 to List.Items.Count - 1 do
        if List.Selected[Result] then Exit;
      Result := LB_ERR;
    end;procedure TForm1.ListBox1Click(Sender: TObject);
    var
      i: Integer;
    begin
      i := GetFirstSelection(listbox1);
      Edit1.Text := listbox1.Items.Strings[i];
    end;