情形描述:有一个Treeview和两个Listview。操作中都会有将listview中的Listitem拖放到treeview中,在treeview的dragdrop事件中如何确定到底是从哪个listview中拖过来的。

解决方案 »

  1.   

    dragdrop事件有一个source参数,可以使用它判断:
    if source is tree1 then
    ...
    elseif source is tree2 then
    ...
    endif
      

  2.   

    在treeview的dragdrop事件中判断:
    if source is listview1 then
       do something
    elseif source is listview2 then
       do something
    endif
      

  3.   

    if source is tree1 then
    ...
    elseif source is tree2 then
    ...
    endif
      

  4.   

    我用到的事件是OLEDragDrop,这个事件里没有source参数的。
      

  5.   

    1>可以先声明一个的枚举变量:
    Enum DragSource
         cNone=0
         cTreeview1=1
         cListView1=2
         cListView2=3
    End Enum2>定义
    Private dSource as  DragSource3> 在TreeView1_OLEStartDrag 中 dSource=cTreeview1
       在ListView1_OLEStartDrag 中 dSource=cListView1
       在ListView2_OLEStartDrag 中 dSource=cListView2
    4> 在三个控件的OLEDragDrop事件中判断dSourse的值即可知道拖拽来源,
    结束后: dSource=cNone上面是一个思路,我一般是这么做的,不知道是否合适?
      

  6.   

    这个思路我看基本上行,谢谢。
    sworddx(.:RNPA:. Hillinsilence;剑宇潇湘·秋叶原 Reloaded),在什么情况下可能会产生意外情况。
      

  7.   

    例如,从外源(不是从本程序的控件开始)进行OLE拖动,得到的dSource就会不对。不过就你的应用环境来看,这个担心可能是多余的。