注册 登录
编程论坛 C++ Builder

请教各位大侠 如何实现Treeview控件中内容到Listbox控件的拖曳

chenxu215213 发布于 2010-11-14 21:58, 1933 次点击
void __fastcall TForm1::ListBox2DragOver(TObject *Sender, TObject *Source,
      int X, int Y, TDragState State, bool &Accept)
{
    if (Source == ListBox1)
        Accept = TRUE;      // If The Drag source is listbox1 then accept it
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ListBox2DragDrop(TObject *Sender, TObject *Source,
      int X, int Y)
{
    if (Source == ListBox1) // If the source is ListBox1 then deal the drag event
    {
        ListBox2->Items->Add(ListBox1->Items->Strings[ListBox1->ItemIndex]);
    }
}

上面是Listbox控件间的拖曳范例(拖曳源内容拖曳后仍存在)   现在是想从一个Treeview控件选中节点内容拖到Listbox控件 该如何修改啊?  我是初学者  大家提提意见 谢谢啊!
1 回复
#2
rainbow12010-12-27 23:34
void __fastcall TForm1::TreeviewDragOver(TObject *Sender, TObject *Source,
      int X, int Y, TDragState State, bool &Accept)
{
    if (Source == TreeView)
        Accept = TRUE;      // If The Drag source is treeview then accept it
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ListBoxDragDrop(TObject *Sender, TObject *Source,
      int X, int Y)
{
    if (Source == TreeView) // If the source is TreeView then deal the drag event
    {
        ListBox->Items->Add(TreeView->Items->Strings[TreeView->ItemIndex]);
    }
}

标红的是关键,实际上是实现了从TreeView对应的节点内容添加到ListBox相应节点。但原节点内容并没有删除。
1