示例#1
0
        public override void OnMouseDown(CellContext sender, System.Windows.Forms.MouseEventArgs e)
        {
            base.OnMouseDown(sender, e);

            var pressed = e.Button & MouseButtons;

            if (pressed == MouseButtons.None)
            {
                return;
            }

            GridVirtual grid = sender.Grid;

            //Check the control and shift key status
            bool controlPress = ((Control.ModifierKeys & Keys.Control) == Keys.Control &&
                                 (grid.SpecialKeys & GridSpecialKeys.Control) == GridSpecialKeys.Control);

            bool shiftPress = ((Control.ModifierKeys & Keys.Shift) == Keys.Shift &&
                               (grid.SpecialKeys & GridSpecialKeys.Shift) == GridSpecialKeys.Shift);

            //Default click handler
            if (shiftPress == false ||
                grid.Selection.EnableMultiSelection == false)
            {
                //Handle Control key
                bool mantainSelection = grid.Selection.EnableMultiSelection && controlPress;

                //If the cell is already selected and the user has the ctrl key pressed then deselect the cell
                // AlanP: Sep 2013.  Changed the equality test for the active row to be row based rather than actual position
                if (controlPress && grid.Selection.IsSelectedCell(sender.Position) && grid.Selection.ActivePosition.Row != sender.Position.Row)
                {
                    grid.Selection.SelectCell(sender.Position, false);
                }
                else
                {
                    grid.Selection.Focus(sender.Position, !mantainSelection);
                }
            }
            else             //handle shift key
            {
                grid.Selection.ResetSelection(true);

                Range rangeToSelect = new Range(grid.Selection.ActivePosition, sender.Position);
                grid.Selection.SelectRange(rangeToSelect, true);
            }

            // begin scroll tracking only if mouse was clicked
            // in scrollable area
            Rectangle scrollRect = grid.GetScrollableArea();

            if (scrollRect.Contains(e.Location))
            {
                BeginScrollTracking(grid);
            }
        }
示例#2
0
        /// <summary>
        /// Move the scrollbars to the direction specified by the point specified.
        /// Method used by the Mouse multi selection (MouseSelection.cs).
        /// Scroll the grid only if the specified location is outside the visible area.
        /// </summary>
        /// <param name="mousePoint"></param>
        public void ScrollOnPoint(Point mousePoint)
        {
            //Scroll if necesary
            Rectangle scrollRect = m_Grid.GetScrollableArea();

            //[email protected] : In the below if condition, adding DragOffset value also
            // to resolve a defect (when grid is the control which fits into the entire area of screen
            // and the form which holds the grid is maximised, Autoscrolling to one or more sides is not possible)
            //This reduces the scrollable area and when inside the grid at that time also autoscrolling will be triggered.
            if (m_Grid.IsCustomAreaAutoScrollEnabled && !m_Grid.DragSizeRectangle.Contains(mousePoint))
            {
                scrollRect = new Rectangle(scrollRect.X + m_Grid.DragOffset,
                                           scrollRect.Y + m_Grid.DragOffset,
                                           scrollRect.Width - 2 * m_Grid.DragOffset,
                                           scrollRect.Height - 2 * m_Grid.DragOffset);
            }

            int?last = LastVisibleScrollableColumn;

            if (mousePoint.X > scrollRect.Right && (!last.HasValue ||
                                                    last.Value < m_Grid.Columns.Count - 1 || m_Grid.Columns.GetRight(last.Value) > scrollRect.Right))
            {
                CustomScrollLineRight();
            }
            last = LastVisibleScrollableRow;
            if (mousePoint.Y > scrollRect.Bottom && (!last.HasValue ||
                                                     last.Value < m_Grid.Rows.Count - 1 || m_Grid.Rows.GetBottom(last.Value) > scrollRect.Bottom))
            {
                CustomScrollLineDown();
            }
            if (mousePoint.X < scrollRect.Left)
            {
                m_Grid.CustomScrollLineLeft();
            }
            if (mousePoint.Y < scrollRect.Top)
            {
                m_Grid.CustomScrollLineUp();
            }
        }