关于treeview的拖放问题,各位帮忙。 |
尚未結案
|
xiaoqlj
一般會員 發表:10 回覆:19 積分:5 註冊:2004-05-28 發送簡訊給我 |
|
shinjie
資深會員 發表:12 回覆:275 積分:287 註冊:2003-03-19 發送簡訊給我 |
試試
procedure TForm1.TreeView1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if ( Button = mbLeft ) and
( htOnItem in Treeview1.GetHitTestInfoAt( X, Y ) ) then
begin
Treeview1.Selected.Collapse(True); //加入這行
Treeview1.BeginDrag( False );
end;
end;
然後要再展開的話加入
Treeview1.Selected.Expand(True);
------
我將在茫茫人海中尋訪我唯一之靈魂伴侶。 得之;我幸。不得;我命。 |
xiaoqlj
一般會員 發表:10 回覆:19 積分:5 註冊:2004-05-28 發送簡訊給我 |
你好,朋友。合并是会合并了,但,就是无法拖到另一根节点上去了,也就是拖放功能没有了。
我的条件是这样的:
-888 //第一层
-1 //第二层
-2
-3
-999 //第一层
-11 //第二层
-22
-33
我是想把第二层的节点,可以互相拖放,第一层之间不需要拖。这我已处理好了。变成:
-888 //第一层
-1 //第二层
-11 //11和22是从下面这层拖上来的。
-22
-2
-3
-999 //第一层
-33 //第二层 11和22是从下面这层拖上来的。要拖的同时,要把999这层合并,拖好后再展开。用了你的方法,合并会了,但拖放功能失效了。
------
http://www.nbye.net |
shinjie
資深會員 發表:12 回覆:275 積分:287 註冊:2003-03-19 發送簡訊給我 |
|
xiaoqlj
一般會員 發表:10 回覆:19 積分:5 註冊:2004-05-28 發送簡訊給我 |
楼上的朋友你好,下午突然有事,出去办事了。到现在才看你回的贴。
我的代码如下:(代码复制后空格都缩进了,可能看起来会比较累。)
unit UNetChat; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ActnList, ToolWin, ActnMan, ActnCtrls, ActnMenus,
XPStyleActnCtrls, jpeg, ExtCtrls, StdCtrls, ComCtrls, ImgList, DB, ADODB; type
PMyRecord =^TMyRecord;
TMyRecord =record
CHAT_ID :Integer;
CHAT_CODE :String;
CHAT_CALLED :String;
end; type
TfrmNetChat = class(TForm)
ActionManager1: TActionManager;
ActionMainMenuBar1: TActionMainMenuBar;
ALogin: TAction;
ALogout: TAction;
AState: TAction;
AFront: TAction;
AOnLine: TAction;
AExit: TAction;
ASendMsg: TAction;
AVoice: TAction;
AVideo: TAction;
ASendFile: TAction;
ASendMail: TAction;
AShare: TAction;
ANewsPrint: TAction;
AHistory: TAction;
AShareMe: TAction;
ADelman: TAction;
AProperty: TAction;
ASendAll: TAction;
ASendSIM: TAction;
AGuide: TAction;
AOption: TAction;
AHelp: TAction;
AUseItem: TAction;
AAboutNet: TAction;
Image1: TImage;
Image2: TImage;
Label1: TLabel;
Label2: TLabel;
StatusBar1: TStatusBar;
TreeView: TTreeView;
ImageList1: TImageList;
TreeQuery1: TADOQuery;
TreeQuery2: TADOQuery;
Button1: TButton;
procedure AExitExecute(Sender: TObject);
procedure TreeViewExpanded(Sender: TObject; Node: TTreeNode);
procedure TreeViewCollapsed(Sender: TObject; Node: TTreeNode);
procedure TreeViewClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure TreeViewDragDrop(Sender, Source: TObject; X, Y: Integer);
procedure TreeViewDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure TreeViewMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
Tree_X,Tree_Y:Integer; //判定treeview的空白区不能激发单击事件。
procedure Show_TreeView();
{ Private declarations }
public
{ Public declarations }
end; var
frmNetChat: TfrmNetChat;
const USER_ID=1; implementation uses DataMod_UNIT; {$R *.dfm} procedure TfrmNetChat.AExitExecute(Sender: TObject);
begin
Application.Terminate;
end; procedure TfrmNetChat.TreeViewExpanded(Sender: TObject; Node: TTreeNode);
begin
IF Node.Level=0 THEN
begin
Node.ImageIndex:=1;
Node.SelectedIndex:=1;
end;
end; procedure TfrmNetChat.TreeViewCollapsed(Sender: TObject; Node: TTreeNode);
begin
IF Node.Level=0 THEN
begin
Node.ImageIndex:=0;
Node.SelectedIndex:=0;
end;
end; procedure TfrmNetChat.TreeViewClick(Sender: TObject);
begin
{if (TreeView.Items.Count>0) and (TreeView.Selected.Level=0) and (htOnItem in TreeView.GetHitTestInfoAt(Tree_X,Tree_Y)) then
begin
if TreeView.Selected.Expanded=false then
Treeview.Selected.Expand(false)
else
Treeview.Selected.Collapse(false);
end; }
end; procedure TfrmNetChat.Show_TreeView;
var
MyRecordPointer:PMyRecord;
FirstNode:TTreeNode;
FriendList,FriendUser:String;
FriendLength:Integer;
begin
TreeView.Items.Clear;
TreeQuery1.Close;
TreeQuery1.SQL.Clear;
TreeQuery1.SQL.Add('SELECT GROUPID,GROUPNAME,FRIEND FROM T_GROUP WHERE ID=' IntToStr(USER_ID) ' ORDER BY PAIXU_ID');
TreeQuery1.Open;
WHILE NOT TreeQuery1.Eof DO
BEGIN
FriendList:=TreeQuery1.FieldByName('FRIEND').AsString;
FirstNode:=TreeView.Items.Add(nil,TreeQuery1.FieldByName('GROUPNAME').AsString);
WHILE Pos(',',FriendList)>0 DO
BEGIN
FriendLength:=Pos(',',FriendList);
FriendUser:=Copy(FriendList,1,FriendLength-1);
TreeQuery2.Close;
TreeQuery2.SQL.Clear;
TreeQuery2.SQL.Add('SELECT ID,CODE,CALLED,ONLINE FROM T_USER WHERE ID=' FriendUser);
TreeQuery2.Open;
New(MyRecordPointer);
MyRecordPointer.CHAT_ID:=TreeQuery2.FieldByName('ID').AsInteger;
MyRecordPointer.CHAT_CODE:=TreeQuery2.FieldByName('CODE').AsString;
MyRecordPointer.CHAT_CALLED:=TreeQuery2.FieldByName('CALLED').AsString;
WITH Treeview.Items.AddChildObject(FirstNode,MyRecordPointer.CHAT_CALLED,MyRecordPointer) DO
BEGIN
IF TreeQuery2.FieldByName('ONLINE').AsString='1' THEN
BEGIN
ImageIndex:=FirstNode.level 2;
SelectedIndex:=FirstNode.level 2;
END
ELSE
BEGIN
ImageIndex:=FirstNode.level 3;
SelectedIndex:=FirstNode.level 3;
END;
END;
Delete(FriendList,1,FriendLength);
END;
TreeQuery1.Next;
END;
end; procedure TfrmNetChat.Button1Click(Sender: TObject);
begin
frmNetChat.Show_TreeView;
end; procedure TfrmNetChat.FormCreate(Sender: TObject);
begin
TreeView.Items.Clear;
end; procedure TfrmNetChat.TreeViewDragDrop(Sender, Source: TObject; X,
Y: Integer);
var
AttachMode : TNodeAttachMode;
begin
if Treeview.Selected=nil then //没有选中,退出本过程。
Exit;
if Treeview.Selected.Level=1 then//限制条件,表示只能拖第二层。取掉表示不限制。
begin
AttachMode:=naAddChild;
Treeview.Items.BeginUpdate;
try
if Treeview.DropTarget.Level=0 then //限制只能放在第一层下面。
Treeview.Selected.MoveTo(Treeview.DropTarget,AttachMode);
finally
Treeview.Items.EndUpdate;
end;
end;
end; procedure TfrmNetChat.TreeViewDragOver(Sender, Source: TObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
var
Node:TTreeNode;
begin
if Source=Treeview then
begin
if Treeview.Selected.Level=1 then//限制条件,表示只能拖第二层。取掉表示不限制。
begin
Node:=Treeview.GetNodeAt(X,Y);
if Node<>nil then
begin
Accept:=True;
end;
end;
end;
end; procedure TfrmNetChat.TreeViewMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
Tree_X:=X;
Tree_Y:=Y;
if ( Button = mbLeft ) and (TreeView.Selected.Level=1) and ( htOnItem in Treeview.GetHitTestInfoAt( X, Y ) ) then
begin
Treeview.Selected.Parent.Collapse(false); //加入這行
Treeview.BeginDrag( False );
end;
end; end. 發表人 - xiaoqlj 於 2005/03/10 04:11:24 發表人 - xiaoqlj 於 2005/03/10 04:13:10
------
http://www.nbye.net |
shinjie
資深會員 發表:12 回覆:275 積分:287 註冊:2003-03-19 發送簡訊給我 |
|
xiaoqlj
一般會員 發表:10 回覆:19 積分:5 註冊:2004-05-28 發送簡訊給我 |
|
xiaoqlj
一般會員 發表:10 回覆:19 積分:5 註冊:2004-05-28 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |