我想作一个类似文件管理器的界面,左边是treeview右边是listview如何实现从右边拖一个东东到左边的treeview中???如何得知用户将东东放在了treeview的哪个item中,以及用户拖来的是listview中的哪个项?
最好能给出简单例程!
//如下:
implementation
{$R *.DFM}
procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then
begin
Listbox1.DragMode := dmManual;
Listbox1.BeginDrag(False, -1);
end;
end;
procedure TForm1.Label1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
if (Sender is TLabel) and (Source is TListBox) then
begin
with Sender as TLabel do
begin
Font := (Source as TListBox).Font;
Color := (Source as TListBox).Color;
Caption := (Source as TListBox).Items[(Source as TListBox).ItemIndex]
end;
end;
end;
procedure TForm1.Label1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := Source is TListBox;
end;
procedure TForm1.TreeView1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := Source is TListBox;
end;
procedure TForm1.TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
With (Sender as TTreeView) do
begin
GetNodeAt(X, Y).Text := (Source as TListBox)
.Items[(Source as TListBox).ItemIndex];
end;
end;
procedure TForm1.TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
With (Sender as TTreeView) do
begin
Items.AddChild(GetNodeAt(X, Y), (Source as TListBox)
.Items[(Source as TListBox).ItemIndex]);
end;