API version 1

- ‐

RW

boolean

dragEnabled

ツリーアイテムがドラッグ可能かどうかを指定します。

trueの時はドラッグできますが、falseの時はドラッグできません。

初期値はfalseです。

関連項目

Droppedイベント



使用例 CRSダウンロード

Form TreeView_dragEnabled {
   X = 0;
   Y = 0;
   width = 800;
   height = 600;

   TreeView treeView1 {
           x = 8;
           y = 8;
           width = 320;
           height = 480;

           # アイテムのドラッグを可能にします
           dragEnabled = true;

           acceptDrop = DisplayObject.DROP_OBJECT + DisplayObject.DROP_MOVEMODE + DisplayObject.DROP_COPYMODE;

           var item1 = rootItem.append("item1-1");
           var item11 = item1.append("item1-11");
           var item2 = rootItem.append("item1-2");
           var item21 = item2.append("item1-21");
           rootItem.expandAll();

           function onClicked(e) {
                   print(name + ": id=" + str(e.item.id) + ", title=" + e.item.title + " がクリックされました");
           };

           function onDropped(e) {
                   ^.processDropped(e, this);
           }
   }

   TreeView treeView2 {
           x = 336;
           y = 8;
           width = 320;
           height = 480;

           dragEnabled = true;

           acceptDrop = DisplayObject.DROP_OBJECT + DisplayObject.DROP_MOVEMODE + DisplayObject.DROP_COPYMODE;

           var item1 = rootItem.append("item2-1");
           var item11 = item1.append("item2-11");
           var item2 = rootItem.append("item2-2");
           var item21 = item2.append("item2-21");
           rootItem.expandAll();

           function onClicked(e) {
                   print(name + ": id=" + str(e.item.id) + ", title=" + e.item.title + " がクリックされました");
           };

           function onDropped(e) {
                   ^.processDropped(e, this);
           }
   }

   function processDropped(e, treeDropped) {
           var item = e.data;
           var itemAt = e.dropitem;
           var position = e.dropitemPosition;

           if (!(item instanceof TreeItem)) {
                   print("TreeItem ではないオブジェクトがドロップされました");
                   return;
           }

           print(item.owner.name + " の " + item.title + " が " + treeDropped.name + " にドロップされました。");

           if (e.mode == DisplayObject.DROP_MOVEMODE && isDescendant(item, itemAt)) {
                   print("同一、または子孫の要素に対する移動はできません");
                   return;
           }
           insertItemToTree(item, itemAt, position);
           if (e.mode == DisplayObject.DROP_MOVEMODE) {
                   print("DROP_MOVEMODE のため元の TreeView(" + item.owner.name + ")側の " + item.title + " は削除されます");
                   item.delete();
           }
   }

   function insertItemToTree(item, itemAt, position)
   {
           var itemToExpand = null;
           if (position == DisplayObject.DROP_ABOVE_ITEM) {
                   itemToExpand = itemAt.insert(item);
           } else if (position == DisplayObject.DROP_ON_ITEM) {
                   itemAt.append(item);
                   itemToExpand = itemAt;
           } else if (position == DisplayObject.DROP_BELOW_ITEM) {
                   var next = itemAt.next;
                   if (next == null) {
                           var parent = itemAt.parent;
                           itemToExpand = parent.append(item);
                   } else {
                           itemToExpand = next.insert(item);
                   }
           }
           itemToExpand.expandAll();
   }

   function isDescendant(itemAncestor, itemDescendant)
   {
           if (!(itemAncestor instanceof TreeItem && itemDescendant instanceof TreeItem)) {
                   return false;
           }

           #引数で与えられたTreeItemのownerを比較する
           if (itemAncestor.owner.name != itemDescendant.owner.name) {
                   return false;
           }

           var itemRoot = itemAncestor.owner.rootItem;
           var itemCurrent = itemDescendant;
           while (itemCurrent.id != itemRoot.id) {
                   if (itemCurrent.id == itemAncestor.id) {
                           return true;
                   }
                   itemCurrent = itemCurrent.parent;
           }
           return false;
   }
}