从ListView到TreeView的拖动代码

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值