如何将列表框1中的项目拖到列表框2中,同时可拖一项或多项? (200分)

  • 主题发起人 我是笨猪
  • 开始时间

我是笨猪

Unregistered / Unconfirmed
GUEST, unregistred user!
1.如何将列表框1中的项目拖到列表框2中,同时可拖一项或多项?
2.还有如何列表框有水平滚动条?
加一个问题
3.是在选择了多项时,想再次单击准备拖时,却变成了重新选中这一项。(就是在有了
选中的项目,单击时不再重新选择项目或选择已选中的项目后进入拖放过程)不知说的是
否清楚^_^
 
用DragDrop试试
 
说详细些,或给出源码?
主要是如何判断框1中有哪些选中
 
建议你看一看Delphi拖动方面的技术;
用一个动态数组就可以实现;
方法用上边的;
 
to  shongyi Delphi拖动方面不是问题,在其它的工具是实现过,主要
是如何判断框1中有哪些项目选中(学DELPHI时间不多)
 
将列表框的dragmode属性改为dmAutomatic,再在dragdrop事件中接收拖过来的项目
添加水平滚动条:
if listbox.items.count=0 then exit;
maxwidth := 0;
for i:=0 to listbox.items.count-1 do
if maxwidth < listbox.canvas.textwidth(listbox.items.string) then
maxwidth := listbox.canvas.textwidth(listbox.items.string);
sendmessage(listbox.handle,LB_SETHORIZONTALEXTENT, maxwidth+2,0);
 
http://wolfsoft.nugoo.com/多个地自己处理一下吧
unction TForm1.AddTo(List: TCustomListBox; str: string): Boolean;
begin
Result:=List.Items.IndexOf(str)<0; //&amp;Aring;&amp;ETH;&amp;para;&amp;Iuml;&amp;Oacute;&amp;ETH;&amp;Atilde;&amp;raquo;&amp;Oacute;&amp;ETH;&amp;Ouml;&amp;Oslash;&amp;cedil;&amp;acute;
if Result then
List.Items.Add(str);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox1.Items.Add('One');
ListBox1.Items.Add('Two');
ListBox1.Items.Add('Three');
ListBox1.Items.Add('Four');
ListBox1.Items.Add('Five');
ListBox1.Items.Add('Six');
CheckListBox1.Items.Add('Russion');
CheckListBox1.Items.Add('English');
end;

procedure TForm1.CheckListBox1DragDrop(Sender, Source: TObject; X,
Y: Integer);
var
nItem:Integer;
begin
if Source=ListBox1 then
begin
nItem:=ListBox1.ItemIndex;
if AddTo(CheckListBox1,ListBox1.Items[nItem]) then
ListBox1.Items.Delete(nItem);
end;
end;

procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept:=True;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
var
nItem:Integer;
begin
for nitem:=0 to listbox1.items.count-1 do
if AddTo(CheckListBox1,ListBox1.Items[nItem]) then
ListBox1.Items.Delete(nItem);
end;
 
部分选择
listbox1.copyselection(listbox2);
listbox1.deleteselected;
全选
listbox1.items.text:=listbox2.items.text;
listbox1.items.clear;
 
好象是用消息处理的
 
呵呵看看大富翁离线数据库上面有
还有,
你不是又浪费了200分,来之不易啊!
 
to ugvanxk
listbox1.copyselection(listbox2);
listbox1.deleteselected;只能在D6中,D5中如何做?
 
没人理我吗?
请大伙给个建议
 
1.
procedure TForm1.ListBox2DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
if (Sender is TListBox) then
begin
listbox2.Items.add(listbox1.Items[listbox1.ItemIndex]);
listbox1.Items.Delete(listbox1.ItemIndex);
end;
end;
procedure TForm1.ListBox2DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
if (Sender is TListbox) then Accept:=True else Accept:=False;
end;

2.设置水平滚动条
procedure TForm1.SetHoScroolBar(Sender:TForm);
var
i,j,MaxWidth: integer;
begin
MaxWidth := 0;
for i:=0 to Sender.ComponentCount-1 do
begin
if Sender.Components is TCheckListBox then
begin
for j := 0 to (Sender.Components as TCheckListBox).Items.Count - 1 do
if MaxWidth < (Sender.Components as TCheckListBox).Canvas.TextWidth((Sender.Components as TCheckListBox).Items.Strings[j]) then
MaxWidth := (Sender.Components as TCheckListBox).Canvas.TextWidth((Sender.Components as TCheckListBox).Items.Strings[j]);
SendMessage((Sender.Components as TCheckListBox).Handle, LB_SETHORIZONTALEXTENT, MaxWidth+2, 0);
end;
end;
end;
3.listbox1的DragMode=dmAutomatic;
4.
单选:itemIndex
多选:哪些被选中 listbox1.Selected 做个循环
 
见老贴:
http://www.delphibbs.com/delphibbs/dispq.asp?lid=505758
 
dragdrop控件
 
to aerobull,Nstar
我要拖多项。
 
多人接受答案了。
 
顶部