CSDN博客

img jvict

从ListView到TreeView的拖动代码

发表于2004/9/18 22:32:00  922人阅读

http://community.csdn.net/Expert/topic/2687/2687080.xml?temp=.9894525

从ListView到TreeView的拖动代码
//---------------------------------------------------------------------------

#include
#pragma hdrstop

#include "Main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
??? TreeView1->Selected = TreeView1->Items->Item[0];
}
//---------------------------------------------------------------------------

void __fastcall TForm1::TreeView1DragOver(TObject *Sender, TObject *Source,
??????????? int X, int Y, TDragState State, bool &Accept)
{
??? if (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;
??? if (Source == TreeView1) {
??????? for (size_t index = 0; index != TreeView1->SelectionCount; ++index) {
??????????? TTreeNode* pNode = TreeView1->Selections[index];
??????????? if (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 states;
??????? states<??????? while (ListView1->SelCount != 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 = TreeView1->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

0 0

相关博文

我的热门文章

img
取 消
img