Drag code from ListView to TreeView

xiaoxiao2021-03-06  51

Http://community.9cbs.net/expert/topic/2687/2687080.xml?temp=.9894525

Drag code from ListView to TreeView // -------------------------------------- -----------------------------------

#include

#pragma HDRSTOP

#include "main.h" // ----------------------------------------- ---------------------------------- # Pragma package (smart_init) #pragma resource "* .dfm" TFORM1 * Form1; // -------------------------------------------------------------------------------------------------------------------------------------- -----------------------------__ fastcall tform1 :: tform1 (tcomponent * oowner: tform (owner) {??? TreeView1- > SELECTED = TreeView1-> items-> item [0];} // ------------------------------- ------------------------------------------

void __fastcall tform1 :: treec {s, ??????????? INT X, INT Y, TDRAGSTATE, BOOL & Accept) {??? f (source == listview1 || Source == TreeView1) ???? Accept = true; ??? Else ???? Accept = false;} // ---------------------- -------------------------------------------------- ---

?

Void __fastcall tform1 :: TreeView1Dragdrop (TOBJECT * Sender, TOBJECT * SOURCE, ????? INT X, INT Y) {??? Ttreenode * pdest = TreeView1-> getnodeat (x, y); ??? IF (! PDEST || PDEST-> Level! = 0) Return; ??? = f (Source == TreeView1) {??????? for (SIZE_T INDEX = 0; Index! = TreeView1-> Selectioncount; Index) {??????????? Ttreenode * pnode = treec = TreeView1-> selects [index]; ??????????? f (pnode-> level! = 0) ????? ?????????? pnode-> moveto (pdest, naaddchild); ???????} ???} ??? else if (source == listview1) {?????? ? Ttreenode * pParent = treeView1-> selected; ??????? if (! Pparent) return; ??????? while (pParent-> level! = 0) ????????? ?? pparent = pParent-> parent; ??????? TListItem * pitem = listview1-> selected; ??????? titemstates stat; ?????? states sellfount! = 0) {

??????????? pParent-> item [pitem-> index] -> MoveTo (pdest, naaddchild);

??????????? TListItem * pTEMP = PITEM;

??????????? pitem = listview1-> getNextitem (PiteM, SDBELOW, STATES);

??????????? pTEMP-> delete ();

???????}

???}

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

Void __fastcall tform1 :: TreeView1click (TOBJECT * Sender) {??? listview1-> items-> clear (); ??? ttreenode * pnode = treaiView1-> selected; ??? if (! pnode || pnode-> level ! = 0) RETURN; ??? for (ttreenode * pchild = pnode-> getfirstchild (); pchild; pchild = pchild-> getNextSibling ()) {??????? TListItem * pitem = listview1-> items- > Add (); ??????? pitem-> caption = pchild-> text; ???}} // --------------------- -------------------------------------------------- ----

DragMode = DMautomatic

转载请注明原文地址:https://www.9cbs.com/read-115551.html

New Post(0)