Example #1
0
        // Starts a drag operation if the mouse leaves the drag box with the button held down.
        void grid_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            if (!grid.DragRectangle.IsEmpty && !grid.DragRectangle.Contains(e.Location))
            {
                bool hitSelectedRow = grid.IsRowSelected(grid.DragRow);

                // The drag data has to be computed when the mouse moves out of the drag rectangle, not on MouseDown,
                // because we need to wait for the mouse down to possibly affect the selection (such as extending it
                // or contracting it, which are done at MouseDown time).
                var rows = new List <WordListEntry>();
                if (hitSelectedRow)
                {
                    // TODO: This won't include the row currently being edited, if one exists!
                    foreach (int row in SelectedEntryIndices)
                    {
                        rows.Add(source[row]);
                    }
                }
                else
                {
                    // TODO: For now, let's not try to drag uncommitted rows.
                    if (grid.DragRow < 0 || grid.DragRow > source.Count)
                    {
                        return;
                    }

                    rows.Add(source[grid.DragRow]);
                    grid.SelectRow(grid.DragRow);
                }

                dragData = new WordListEntries(source, rows);
                var data = dragData.MakeDataObject();

                var result = grid.DoDragDrop(data, DragDropEffects.Move | DragDropEffects.Copy | DragDropEffects.Scroll);

                // If we moved the items, we have to delete the original ones now.
                // This doesn't exactly look great in the undo list, but it's very unlikely that
                // we'll be able to tie together undo items related to multiple lists.
                if (result == DragDropEffects.Move)
                {
                    var indices = new List <int>();
                    foreach (var entry in dragData.Items)
                    {
                        int i = source.IndexOf(entry);
                        indices.Add(i);
                    }

                    source.RemoveAt(indices);
                }
            }
        }
Example #2
0
        // Starts a drag operation if the mouse leaves the drag box with the button held down.
        void grid_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
                return;

            if (!grid.DragRectangle.IsEmpty && !grid.DragRectangle.Contains(e.Location)) {
                bool hitSelectedRow = grid.IsRowSelected(grid.DragRow);

                // The drag data has to be computed when the mouse moves out of the drag rectangle, not on MouseDown,
                // because we need to wait for the mouse down to possibly affect the selection (such as extending it
                // or contracting it, which are done at MouseDown time).
                var rows = new List<WordListEntry>();
                if (hitSelectedRow) {
                    // TODO: This won't include the row currently being edited, if one exists!
                    foreach (int row in SelectedEntryIndices)
                        rows.Add(source[row]);
                } else {
                    // TODO: For now, let's not try to drag uncommitted rows.
                    if (grid.DragRow < 0 || grid.DragRow > source.Count)
                        return;

                    rows.Add(source[grid.DragRow]);
                    grid.SelectRow(grid.DragRow);
                }

                dragData = new WordListEntries(source, rows);
                var data = dragData.MakeDataObject();

                var result = grid.DoDragDrop(data, DragDropEffects.Move | DragDropEffects.Copy | DragDropEffects.Scroll);

                // If we moved the items, we have to delete the original ones now.
                // This doesn't exactly look great in the undo list, but it's very unlikely that
                // we'll be able to tie together undo items related to multiple lists.
                if (result == DragDropEffects.Move) {
                    var indices = new List<int>();
                    foreach (var entry in dragData.Items) {
                        int i = source.IndexOf(entry);
                        indices.Add(i);
                    }

                    source.RemoveAt(indices);
                }
            }
        }