我有两个列表框,想实现这样的功能,如果选中几项就通过一个按钮把它移动到另一个列表框中,还有一个按钮能实现全部移动的功能。另外,再把这些选中的项插入到库里。谢谢!一解决,马上给分!

解决方案 »

  1.   

    先用Add或Insert将选中的项加入新列表;
    再用Delete从旧列表删除;
    如果是多项的话就用循环.
      

  2.   

    // for Delphi 7// 移动被选中项
    procedure TForm1.Button1Click(Sender: TObject);
    var
      I: Integer;
    begin
      for I := 0 to ListBox1.Items.Count - 1 do
      begin
        if ListBox1.Selected[I] then
          ListBox2.Items.Add(ListBox1.Items[I]);
      end;
      ListBox1.DeleteSelected;
    end;// 移动所有项
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      ListBox2.Items.Text := ListBox2.Items.Text + ListBox1.Items.Text;
      ListBox1.Items.Clear;
    end;
      

  3.   

    采取一种折中的方法,一个列表框里删除,一个添加procedure Tfrmcjpz.move(lb1,lb2:tlistbox);
    var icount:integer;
    begin
      icount := lb1.ItemIndex;
      if icount>=0 then
      begin
        lb2.Items.Append(lb1.Items.Strings[icount]);
        lb1.Items.Delete(icount);
      end;
      if lb1.Items.Count>0 then
        lb1.ItemIndex := icount;
      if listbox4.Count>0 then btnprior.Enabled := false
      else btnprior.Enabled := true;
    end;
      

  4.   

    谢谢楼上几位:
    我怎么样实现按住Shift键进行连选呢?
      

  5.   

    在OnSelectOneItem()中可以触发Ctrl连选,不行就OnKeyPress().
      

  6.   

    谢谢你,mf78Boy!
    楼上的各位朋友:我怎样实现移动的同时,再把这些项再写到对应的数据库中呢?
      

  7.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      I: Integer;
    begin
      for I := 0 to ListBox1.Items.Count - 1 do
      begin
        if ListBox1.Selected[I] then
          ListBox2.Items.Add(ListBox1.Items[I]);
      end;
      With Query1 do
      beign
        Sql.Clear;
        Sql.Add(format('insert into tablename (aa) values (''%s'')',[ListBox1.Items[i]]));
      end;
      ListBox1.DeleteSelected;
    end;
      

  8.   

    to jiaclassmate(jia):
    运行时出现List index out of bounds(17)这样的错误。
      

  9.   

    双击query后,add fields看看能不能解决!
      

  10.   

    还有当listbox1中已有和listbox2中相同的项时,listbox2中项就不能添加到listbox1中,这个应该怎么实现呢?