Example #1
0
        private void OnDragDrop(object sender, DevExpress.Utils.DragDrop.DragDropEventArgs e)
        {
            var indexes = e.GetData <IEnumerable <int> >();

            if (indexes == null)
            {
                return;
            }
            var destNode  = GetDestNode(e.Location);
            int destIndex = CalcDestNodeIndex(e, destNode);

            treeList.BeginUpdate();

            foreach (int _index in indexes)
            {
                var person   = gridDataSource[_index];
                int parentID = -1;
                if (destNode != null)
                {
                    parentID = (int)destNode["ID"];
                }
                TreeListNode node = treeList.AppendNode(new PersonEx(person, parentID).ToArray(), destIndex == -1000 ? destNode : null);
                if (destIndex > -1)
                {
                    treeList.MoveNode(node, destNode.ParentNode, true, destIndex);
                    destIndex++;
                }
                if (node.ParentNode != null)
                {
                    node.ParentNode.Expand();
                }
            }
            treeList.EndUpdate();
        }
        private void Behavior_DragDrop(object sender, DevExpress.Utils.DragDrop.DragDropEventArgs e)
        {
            GridView targetGrid = e.Target as GridView;
            GridView sourceGrid = e.Source as GridView;

            if (e.Action == DragDropActions.None || targetGrid != sourceGrid)
            {
                return;
            }
            DataTable sourceTable = sourceGrid.GridControl.DataSource as DataTable;

            Point       hitPoint = targetGrid.GridControl.PointToClient(Cursor.Position);
            GridHitInfo hitInfo  = targetGrid.CalcHitInfo(hitPoint);

            int[] sourceHandles = e.GetData <int[]>();

            int targetRowHandle = hitInfo.RowHandle;
            int targetRowIndex  = targetGrid.GetDataSourceRowIndex(targetRowHandle);

            List <DataRow> draggedRows = new List <DataRow>();

            foreach (int sourceHandle in sourceHandles)
            {
                int     oldRowIndex = sourceGrid.GetDataSourceRowIndex(sourceHandle);
                DataRow oldRow      = sourceTable.Rows[oldRowIndex];
                draggedRows.Add(oldRow);
            }

            int newRowIndex;

            switch (e.InsertType)
            {
            case InsertType.Before:
                newRowIndex = targetRowIndex > sourceHandles[sourceHandles.Length - 1] ? targetRowIndex - 1 : targetRowIndex;
                for (int i = draggedRows.Count - 1; i >= 0; i--)
                {
                    DataRow oldRow = draggedRows[i];
                    DataRow newRow = sourceTable.NewRow();
                    newRow.ItemArray = oldRow.ItemArray;
                    sourceTable.Rows.Remove(oldRow);
                    sourceTable.Rows.InsertAt(newRow, newRowIndex);
                }
                break;

            case InsertType.After:
                newRowIndex = targetRowIndex < sourceHandles[0] ? targetRowIndex + 1 : targetRowIndex;
                for (int i = 0; i < draggedRows.Count; i++)
                {
                    DataRow oldRow = draggedRows[i];
                    DataRow newRow = sourceTable.NewRow();
                    newRow.ItemArray = oldRow.ItemArray;
                    sourceTable.Rows.Remove(oldRow);
                    sourceTable.Rows.InsertAt(newRow, newRowIndex);
                }
                break;

            default:
                newRowIndex = -1;
                break;
            }
            int insertedIndex = targetGrid.GetRowHandle(newRowIndex);

            targetGrid.FocusedRowHandle = insertedIndex;
            targetGrid.SelectRow(targetGrid.FocusedRowHandle);
        }