1. 程式人生 > >DevExpress XtraTreeList 節點拖拽

DevExpress XtraTreeList 節點拖拽

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Nodes;

namespace DragDropReorder {
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form {
        private DevExpress.XtraTreeList.TreeList treeList1;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public Form1() {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing ) {
            if( disposing ) {
                if (components != null) {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent() {
            this.treeList1 = new DevExpress.XtraTreeList.TreeList();
            ((System.ComponentModel.ISupportInitialize)(this.treeList1)).BeginInit();
            this.SuspendLayout();
            // 
            // treeList1
            // 
            this.treeList1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.treeList1.Location = new System.Drawing.Point(0, 0);
            this.treeList1.Name = "treeList1";
            this.treeList1.Size = new System.Drawing.Size(422, 277);
            this.treeList1.TabIndex = 0;
            this.treeList1.CalcNodeDragImageIndex += new DevExpress.XtraTreeList.CalcNodeDragImageIndexEventHandler(this.treeList1_CalcNodeDragImageIndex);
            this.treeList1.DragOver += new System.Windows.Forms.DragEventHandler(this.treeList1_DragOver);
            this.treeList1.DragDrop += new System.Windows.Forms.DragEventHandler(this.treeList1_DragDrop);
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(422, 277);
            this.Controls.Add(this.treeList1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.treeList1)).EndInit();
            this.ResumeLayout(false);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() {
            Application.Run(new Form1());
        }

        private void Form1_Load(object sender, System.EventArgs e) {
            new DevExpress.XtraTreeList.Design.XViews(treeList1);
            treeList1.OptionsBehavior.DragNodes = true;
        }

        private DragDropEffects GetDragDropEffect(TreeList tl, TreeListNode dragNode) {
            TreeListNode targetNode;
            Point p = tl.PointToClient(MousePosition);
            targetNode = tl.CalcHitInfo(p).Node;

            if(dragNode != null && targetNode != null 
                && dragNode != targetNode
                && dragNode.ParentNode == targetNode.ParentNode)
                return DragDropEffects.Move;
            else
                return DragDropEffects.None;
        }

        private void treeList1_DragOver(object sender, System.Windows.Forms.DragEventArgs e) {
            TreeListNode dragNode = e.Data.GetData(typeof(TreeListNode)) as TreeListNode;
            e.Effect = GetDragDropEffect(sender as TreeList, dragNode);
        }

        private void treeList1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) {
            TreeListNode dragNode, targetNode;
            TreeList tl = sender as TreeList;
            Point p = tl.PointToClient(new Point(e.X, e.Y));
            
            dragNode = e.Data.GetData(typeof(TreeListNode)) as TreeListNode;
            targetNode = tl.CalcHitInfo(p).Node;
            
            tl.SetNodeIndex(dragNode, tl.GetNodeIndex(targetNode));
            e.Effect = DragDropEffects.None;
        }

        private void treeList1_CalcNodeDragImageIndex(object sender, DevExpress.XtraTreeList.CalcNodeDragImageIndexEventArgs e) {
            TreeList tl = sender as TreeList;
            if(GetDragDropEffect(tl, tl.FocusedNode) == DragDropEffects.None)
                e.ImageIndex = -1;  // no icon
            else
                e.ImageIndex = 1;  // the reorder icon (a curved arrow)
        }
    }
}

相關推薦

DevExpress XtraTreeList 節點

using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data;

Raphaël的動態線條新增,節點

大部分參考:原文地址 首先定義幾個變數: var paper =null; var dragger=null; var move=null; var up=null; var shapes=null; var mouseX=null;//儲存頁面中滑鼠的X軸座標 var

原生js實現節點

var Drags = function (element, callback) { callback = callback || function () {}; var params = {

DevExpress使用經驗分享:Treelist節點

本篇要實現的目標,簡單來說就是把一個的節點用滑鼠拖到另外的節點(自身或其他的listview)上,如下圖: (圖一) (圖二) (圖三) 首先,在視窗中拉入兩個listview,第一個建立三列(上),第二個建立兩列(下),如下圖: 為第一個listview建立一些節點:

C# TreeView 節點到另一個容器Panel中簡單實現

C# TreeView 拖拽節點到另一個容器Panel中簡單實現 用了這麼久C#拖拽功能一直沒有用到也就沒用過,今天因為專案需要,領導特地給我簡單講解了下拖拽功能,真是的大師講解一點通啊。特地寫一篇部落格記錄下,分享給大家!也方便以後自己檢視。 1.拖拽功能分析 拖拽功能分析其實就三個字:選-->

DevExpress學習筆記(五)-以的方式構建樹(TreeList)

DevExpress學習筆記 以拖拽的方式構建樹(TreeList) 本人最近在做某個專案中需要用到動態設定TreeList節點的技術,在這個過程中對於TreeList的各項功能有了初步的嘗試,準備分幾篇內容將其記錄下來。這一篇主要記錄TreeList的拖

easyu tree節點(1)

<div id="treediv"><ul id='tt'></ul></div> <script> var treedata = [{"id":"0","text":"根節點","state":"open",

c# DevExpress.XtraTreeList 樹形節點的上下移動

//向上 private void btnMoveUp_Click(object sender, EventArgs e) { this.treeFile.Columns["LastWriteTime"].SortOrder = SortOrder.None; TreeLi

JavaScript實現網頁元素的效果

wid parseint fontsize current ini .net win == oct 以下的頁面中放了兩個div,能夠通過鼠標拖拽這兩個元素到任何位置。 實現該效果的HTML頁面代碼例如以下所看到的: <!DOCTYPE html> &

事件_2

log || spa agen onload win close list pre 1 *{margin: 0;padding: 0;} 2 li{list-style: none; 3 height: 30px; 4

canvasn效果

鼠標 fun brush int eat 初始 ntb 代碼 class canvas拖拽和平時用的js拖拽是有區別的 普通的js是設置目標為絕對定位,再根據鼠標的移動來改變left和top的值 canvas是獲得了鼠標的位置,直接在目標點進行重新繪制 下面給一個簡單的拖拽

jquery實現對div的功能

func function .org absolut 移動 posit center sed fun <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.o

復制案例

app demo onmouseup function mar red round utf-8 nload <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"

Java實現上傳

itl filename 表單元 ava 100% ondrag nco write obj 原文:http://www.open-open.com/code/view/1437358795584 在項目開發中由於實際需求,需要開發拖拽上傳的功能,ok! 先看效果圖

js 利用jquery.gridly.js實現並且排序

user push idl osi llb ext true js實現 idt <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> &

克隆。

use ack eve console log list pac off ive <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>

JavaScript實現預覽,AJAX小文件上傳

strong 名稱 獲取文件 是否 set 可能 lis idt scrip 本地上傳,提前預覽(圖片。視頻) 1.html中div標簽預覽顯示。button標簽觸發上傳事件。 <div id="drop_area" style=

js原生

javascrip tel ntb script blog window style idt mouseup style樣式 <style type="text/css"> #box{ width: 100px;

cookie結合js 實現記住的

div 位置 highlight cti top mov type logs 加載 哈嘍!!!我胡漢三又回來啦!!!有木有記掛挪啊!咱們今天說一個 cookie結合JS的小案例哦! 話不多說直接上代碼: <!DOCTYPE html> <html>

使用angular幫你實現

highlight 3.1 query 關閉 javascrip brush 返回 sem 改變 拖拽有多種寫法,在這裏就看一看angular版的拖拽。 <!DOCTYPE html> <html ng-app="myApp"> <head