private void GridControl_MouseMove(object sender, MouseEventArgs e)
        {
            if (hitInfo == null || e.Button != MouseButtons.Left)
            {
                return;
            }

            GridControl gc       = sender as GridControl;
            Rectangle   dragRect = new Rectangle(new Point(
                                                     hitInfo.HitPoint.X - SystemInformation.DragSize.Width / 2,
                                                     hitInfo.HitPoint.Y - SystemInformation.DragSize.Height / 2), SystemInformation.DragSize);

            if (!(hitInfo.RowHandle == GridControl.InvalidRowHandle) && !dragRect.Contains(new Point(e.X, e.Y)))
            {
                object gridRow           = gc.FocusedView.GetRow(hitInfo.RowHandle);
                EstimateProjectType pt   = gridRow as EstimateProjectType;
                EstimateCalculator  calc = gridRow as EstimateCalculator;

                Bitmap rowImage = clsDragHelper.GetRowImage((GridView)gc.FocusedView, hitInfo.RowHandle);
                dragCursor     = clsDragHelper.CreateCursor(rowImage, Point.Empty);
                Cursor.Current = dragCursor;

                if (pt != null)
                {
                    gc.DoDragDrop(pt, DragDropEffects.Copy);
                }
                else if (calc != null)
                {
                    gc.DoDragDrop(new EstimateCalculator {
                        EstimateCalculatorId = calc.EstimateCalculatorId, Description = calc.Description
                    }, DragDropEffects.Copy);
                }
            }
        }
        private void TreeList1_DragOver(object sender, DragEventArgs e)
        {
            TreeList tl = sender as TreeList;

            // see if we dragged a GridObject or a TreeListNode
            TreeListNode node = e.Data.GetData(typeof(TreeListNode)) as TreeListNode;

            if (node != null)
            {
                e.Effect = GetDragDropEffect(tl, node);
            }
            else
            {
                EstimateProjectType ept  = e.Data.GetData(typeof(EstimateProjectType)) as EstimateProjectType;
                EstimateCalculator  calc = e.Data.GetData(typeof(EstimateCalculator)) as EstimateCalculator;
                if (ept != null)
                {
                    e.Effect = GetDragDropEffect(tl, ept);
                }
                else
                {
                    e.Effect = GetDragDropEffect(tl, calc);
                }
            }
        }
        /// <summary>
        /// Get drag-drop effect for dragging calculator from grid control
        /// </summary>
        /// <param name="tl">The TreeList control to apply effect to</param>
        /// <param name="dragObject">The grid control row being dragged</param>
        /// <returns></returns>
        private DragDropEffects GetDragDropEffect(TreeList tl, EstimateCalculator dragObject)
        {
            // get node being dragged over
            TreeListNode targetNode;
            Point        p = tl.PointToClient(MousePosition);

            targetNode = tl.CalcHitInfo(p).Node;
            //bool isProject = dragObject is EstimateProjectType;

            // allow drag to project level if from project grid, else calculator level
            bool isOK = (targetNode != null && targetNode.Level == 1);

            // in case of empty project allow dropping into project
            isOK = isOK | (targetNode != null && targetNode.Level == 0);

            return(isOK ? DragDropEffects.Copy : DragDropEffects.None);
        }
        private void TreeList1_CalcNodeDragImageIndex(object sender, CalcNodeDragImageIndexEventArgs e)
        {
            TreeList        tl   = sender as TreeList;
            DXDragEventArgs args = e.DragArgs.GetDXDragEventArgs(tl);
            TreeListNode    node = args.Data.GetData(typeof(TreeListNode)) as TreeListNode;

            // draging treelist item
            if (node != null)
            {
                // invalid drop location, show nothing
                if (GetDragDropEffect(tl, node) == DragDropEffects.None)
                {
                    e.ImageIndex = -1;
                }

                // dropping a child onto a parent, show INSERT arrow
                else if (args.TargetNode.Level == 0 && node.Level > 0)
                {
                    e.ImageIndex = 0;
                }

                // otherwise show AFTER arrow
                else
                {
                    e.ImageIndex = 2;
                }
            }

            // dragging grid row
            else
            {
                EstimateProjectType pt   = args.Data.GetData(typeof(EstimateProjectType)) as EstimateProjectType;
                EstimateCalculator  calc = args.Data.GetData(typeof(EstimateCalculator)) as EstimateCalculator;
                bool isProject           = pt != null;

                //object gridObject = args.Data.GetData(typeof(object));
                // invalid drop location, show nothing
                DragDropEffects dde;
                if (isProject)
                {
                    dde = GetDragDropEffect(tl, pt);
                }
                else
                {
                    dde = GetDragDropEffect(tl, calc);
                }

                if (dde == DragDropEffects.None)
                {
                    e.ImageIndex = -1;  // no icon
                }
                // dropping a CALCULATOR onto a parent, show INSERT arrow
                else if (args.TargetNode.Level == 0 && !isProject)
                {
                    e.ImageIndex = 0;
                }

                // otherwise show AFTER arrow
                else
                {
                    e.ImageIndex = 2;
                }
            }
        }
        private void TreeList1_DragDrop(object sender, DragEventArgs e)
        {
            TreeList        tl         = sender as TreeList;
            DXDragEventArgs args       = e.GetDXDragEventArgs(tl);
            TreeListNode    targetNode = args.TargetNode;

            // get treelist drag node. if null, was dragging from gridcontrol
            TreeListNode dragNode = e.Data.GetData(typeof(TreeListNode)) as TreeListNode;

            // dropping TreeListNode
            if (dragNode != null)
            {
                // get drag and target parents
                TreeListNode dragParent   = dragNode.ParentNode;
                TreeListNode targetParent = targetNode.ParentNode;

                int targetIndex = tl.GetNodeIndex(targetNode);
                int dragIndex   = tl.GetNodeIndex(dragNode);

                // if dropping a parent node
                if (dragParent == null)
                {
                    tl.MoveNode(dragNode, null, true, dragIndex < targetIndex ? targetIndex : targetIndex + 1);
                }

                // if dropping a child node
                else
                {
                    // if dropping child into same parent
                    if (targetParent == dragParent) //  && dragParent != null)
                    {
                        tl.SetNodeIndex(dragNode, dragIndex < targetIndex ? targetIndex : targetIndex + 1);
                    }

                    // if dropping child into different parent
                    else
                    {
                        // dropping on a child of other parent
                        if (targetParent != null && targetParent != dragParent)
                        {
                            tl.MoveNode(dragNode, targetParent, true, tl.GetNodeIndex(targetNode) + 1); // DX: +1 to insert AFTER
                        }
                        // dropping on other parent node
                        if (targetParent == null && targetNode.Level != dragNode.Level) // DX: Insert a node into a root node
                        {
                            tl.MoveNode(dragNode, targetNode, true, 0);
                        }
                    }
                }
                e.Effect = DragDropEffects.None;
            }

            // dropping GridObject
            else
            {
                EstimateProjectType pt   = args.Data.GetData(typeof(EstimateProjectType)) as EstimateProjectType;
                EstimateCalculator  calc = args.Data.GetData(typeof(EstimateCalculator)) as EstimateCalculator;
                if (pt == null && calc == null)
                {
                    return;
                }
                TreeListNode parent = null;
                string       description;
                if (pt != null)
                {
                    description = pt.Description;
                }
                else
                {
                    description = calc.Description;
                }

                TreeListNode newNode = tl.AppendNode(new object[] { description }, parent);
                if (pt == null)
                {
                    newNode.Tag = calc;
                }
                else
                {
                    newNode.Tag = pt;
                }

                if (targetNode != null)
                {
                    // dropping a CALCULATOR grid row onto root node, insert as first child
                    if (targetNode.Level == 0 && calc != null)
                    {
                        tl.MoveNode(newNode, targetNode, true, 0);
                    }

                    // dropping ANY type of grid row on any type of node, insert AFTER
                    else
                    {
                        tl.MoveNode(newNode, targetNode.ParentNode, true, tl.GetNodeIndex(targetNode) + 1);
                    }
                }
            }
            if (targetNode != null && targetNode.HasChildren)
            {
                targetNode.Expanded = true;
            }
            tl.Refresh();
        }