Пример #1
0
        /// <summary>
        /// Handles SuperGrid DragDrop events
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SuperGridControlDragDrop(object sender, DragEventArgs e)
        {
            SuperGridControl sg = sender as SuperGridControl;

            if (sg != null)
            {
                ClearStyles(sg);

                Point       pt   = sg.PointToClient(new Point(e.X, e.Y));
                GridElement item = sg.GetElementAt(pt.X, pt.Y);

                // If the data we are dropping is from a SuperGrid, then
                // be a little bit more discerning about how we drop it

                if (_SrcGrid != null)
                {
                    SelectedElementCollection items =
                        (SelectedElementCollection)e.Data.GetData(typeof(SelectedElementCollection));

                    if (item is GridCell)
                    {
                        if (_SrcElement is GridRow)
                        {
                            DropSgRow(e, ((GridCell)item).GridRow, items);
                        }
                        else
                        {
                            DropSgCell((GridCell)item, items);
                        }
                    }
                    else if (item is GridRow)
                    {
                        DropSgRow(e, (GridRow)item, items);
                    }

                    else if (item is GridColumnHeader)
                    {
                        DropSgColumnHeader((GridColumnHeader)item, items, pt);
                    }

                    else if (item is GridPanel)
                    {
                        DropSgPanel((GridPanel)item, items);
                    }
                }
                else
                {
                    if (item is GridCell)
                    {
                        if (_SrcElement is GridRow)
                        {
                            DropRow(e, ((GridCell)item).GridRow);
                        }
                        else
                        {
                            DropCell(e, (GridCell)item);
                        }
                    }
                    else if (item is GridRow)
                    {
                        DropRow(e, (GridRow)item);
                    }

                    else if (item is GridColumnHeader)
                    {
                        DropColumnHeader(e, (GridColumnHeader)item, pt);
                    }
                }

                ClearDragHighlight();
            }
        }
Пример #2
0
        /// <summary>
        /// Handles SuperGrid DragOver events
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SuperGridControlDragOver(object sender, DragEventArgs e)
        {
            SuperGridControl sg = sender as SuperGridControl;

            if (sg != null)
            {
                ClearDragHighlight();

                e.Effect = DragDropEffects.None;

                Point       clientPoint = sg.PointToClient(new Point(e.X, e.Y));
                GridElement item        = sg.GetElementAt(clientPoint.X, clientPoint.Y);

                if (item is GridCell)
                {
                    if (_SrcElement is GridRow)
                    {
                        item = ((GridCell)item).GridRow;
                    }
                    else if (_SrcElement == null || _SrcElement is GridCell)
                    {
                        _DragOverCell = (GridCell)item;
                        _DragOverCell.CellStyles.Default.Background = new Background(Color.AliceBlue);

                        e.Effect = DragDropEffects.Copy | DragDropEffects.Move;
                    }
                }

                if (item is GridRow)
                {
                    if (_SrcElement == null || _SrcElement is GridRow)
                    {
                        _DragOverRow = (GridRow)item;
                        _DragOverRow.CellStyles.Default.Background = new Background(Color.AliceBlue);

                        e.Effect = DragDropEffects.Copy | DragDropEffects.Move;
                    }
                }
                else if (item is GridColumnHeader)
                {
                    if (_SrcElement is GridColumn)
                    {
                        GridColumn doColumn = ((GridColumnHeader)item).GetHitColumn(clientPoint);

                        if (((GridColumn)_SrcElement).EditorType == doColumn.EditorType)
                        {
                            _DragOverColumn = doColumn;
                            _DragOverColumn.CellStyles.Default.Background = new Background(Color.AliceBlue);

                            e.Effect = DragDropEffects.Copy | DragDropEffects.Move;
                        }
                    }
                    else if (_SrcElement == null || _SrcElement is GridRow)
                    {
                        e.Effect = DragDropEffects.Copy | DragDropEffects.Move;
                    }
                }

                if (sg != _SrcGrid)
                {
                    e.Effect &= ~(DragDropEffects.Move);
                }
                else
                {
                    if ((e.KeyState & 8) != 8)
                    {
                        e.Effect &= ~(DragDropEffects.Copy);
                    }
                }
            }
        }