请教各路豪杰:请问DRAG AND DROP在DELPHI中怎么用?
例如从一个DBgrid向另外一个DBGrid拖拽,请给出简单示例!
另外,我在TreeView中的Expanding事件中添加新接点,我希望
赋值给Node但是他每次都将我要展开的Node的下一级子接点的最后
报告给我,我该怎么做。我不想用Label,如能解决,不胜感激!!

解决方案 »

  1.   

    1.
    http://www.chinaoak.com/download/material/interface/BCBDragDrop.htm
    http://www.ruijier.com/knowledge/program/de4.htm
    2.第二个你要实现什么功能?
      

  2.   

    下面是Delphi提供的例子:
    This code comes from an application that contains a list box and three labels, each with a different font and color.  The DragMode property for each of the labels is dmAutomatic.  The user can select a label and drag it to a list box and drop it. When the label is dropped, the items in the list box assume the color and font of the dropped label. 
    This OnDragOver event handler permits the list box to accept a dropped label:procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);begin
      Accept := Source is TLabel;end;This OnDragDrop event handler implements the drop behavior.procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);begin
      if (Sender is TListBox) and (Source is TLabel) then
      begin
        with Sender as TListBox do
        begin
          Font := (Source as TLabel).Font;
          Color := (Source as TLabel).Color;
        end;
      end;
    end;至于OnExpanding事件,俺不明白你在问什么。俺用该事件没遇到什么问题。
    什么是“Node的下一级子节点的最后报告”?你用Label干什么?倒成了俺提问了。呵呵。
      

  3.   

    不好意思,才回来。我的意思是说:我做的是数据库,界面上面有四个DBGrid分别成对出现,然后从数据库中检索数据。我希望单击点中某个DBGrid中的一行,可以将它以拖拽的形式拉到另一个DBGrid之中。由于拖拽的对象并不是什么特定对象,所以我想问是否需要创建另外的类别什么的?又该用到哪几个函数的呢?比如我曾经在PowerBuilder中做过类似的程序,非常完美而且简单。我当然是不希望用dmAutomatic情况了。
    ---------------------------------1问题如上--------------------------
    我要做的是部门和人员对照关系情况。我的部门有N级,每级以三位字符串递加。编码不会重复,但是部门名称可以不同级重复。我想在左边的树中表现的是分级部门情况,即只有部门名称而不出现部门编码。所以按照以前的习惯我在Form的Create事件中加入了根节点,然后在每次对节点进行展开的时候加入他的子节点也就是在OnExpanding事件中。可是由于我每次添加给树的内容:即表现出来的标题在库中是不唯一的,所以我用到了Data,我希望在我每次展开节点的时候找到我添加的Data,然后通过Data再到数据库中查询,做出相应的动作。可是每次我想在OnExpanding中查找Data时,我发现我总不能得到我点击的那个节点的Data,我得到的是他的子节点的最末Data。或许是我用的不对,或许是其他什么的原因,我始终没有办法解决,请二位大虾帮忙!!!!Data是我按照帮助上面声明的指向Record的一个指针。