protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); HitTestInfo htInfo = this.HitTest(e.X, e.Y); if (htInfo.Type == DataGridViewHitTestType.Cell) { if (htInfo.ColumnIndex != -1 && htInfo.RowIndex != -1) { this.CurrentCell = this[htInfo.ColumnIndex, htInfo.RowIndex]; } } else if (htInfo.Type == DataGridViewHitTestType.ColumnHeader) { if (this.Rows.Count > 0) { int rowIndex = 0; while (true) { if (this.Rows[rowIndex].Visible) { break; } else { rowIndex++; } } this.CurrentCell = this[htInfo.ColumnIndex, rowIndex]; } } else if (htInfo.Type == DataGridViewHitTestType.RowHeader) { int columnIndex = 0; while (true) { if (this.Columns[columnIndex].Visible) { break; } else { columnIndex++; } } this.CurrentCell = this[columnIndex, htInfo.RowIndex]; } }
public override bool CanInsertActivities(HitTestInfo insertLocation, ReadOnlyCollection <Activity> activitiesToInsert) { CompositeActivity compositeActivity = Activity as CompositeActivity; if (compositeActivity != null && compositeActivity.EnabledActivities.Count > 0) { return(false); } if (activitiesToInsert.Count > 1) { return(false); } return(base.CanInsertActivities(insertLocation, activitiesToInsert)); }
public static int DataGridViewMouseDownContextMenu(DataGridView sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { HitTestInfo hitTest = sender.HitTest(e.X, e.Y); sender.ClearSelection(); if (hitTest.RowIndex < 0) { PreventContextMenu(sender, e); return(-1); } sender.Rows[hitTest.RowIndex].Selected = true; return(hitTest.RowIndex); } return(-1); }
/// <summary> /// Makes sure, that the index of the effective clicked row of a DataGridView is returned. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <returns>Index of clicked row in a DataGridView</returns> public static int DataGridViewMouseDownContextMenu(DataGridView sender, MouseEventArgs e) { if (sender == null) { return(-1); } HitTestInfo hitTest = sender.HitTest(e.X, e.Y); sender.ClearSelection(); if (hitTest.RowIndex < 0) { return(-1); } sender.Rows[hitTest.RowIndex].Selected = true; return(hitTest.RowIndex); }
/// <summary> /// Handles the event of a double-click /// </summary> /// <param name="sender">The object that notified of the event</param> /// <param name="e">Attached arguments regarding the event</param> private void DoubleClickHandler(object sender, EventArgs e) { try { Point pt = this.PointToClient(Cursor.Position); HitTestInfo hti = this.HitTest(pt.X, pt.Y); if (hti.Type == DataGridViewHitTestType.Cell) { FireRowDoubleClicked(SelectedBusinessObject); } } catch (Exception ex) { GlobalRegistry.UIExceptionNotifier.Notify(ex, "", "Error "); } }
private void c1FlexGrid1_MouseDown(object sender, MouseEventArgs e) { //Handle Hyperlink click if (Cursor == Cursors.Hand) { HitTestInfo ht = c1FlexGrid1.HitTest(e.X, e.Y); if (ht.Type == HitTestTypeEnum.Cell) { FlexHyperlink link = c1FlexGrid1[ht.Row, ht.Column] as FlexHyperlink; if (link != null) { link.Activate(); } } } }
protected override void WndProc(ref Message m) { if (m.Msg == 0x201) //WM_LBUTTONDOWN = 0x201 { HitTestInfo ht = TryHitTest(m); if (ht.Type == DataGridViewHitTestType.Cell) { downButton = this[ht.ColumnIndex, ht.RowIndex]; if (SelectedCells.Count > 1 && downButton is DataGridViewButtonCell) { InvalidateCell(ht.ColumnIndex, ht.RowIndex); return; } } } else if (m.Msg == 0x202) { downButton = null; //WM_LBUTTONUP = 0x202 } else if (m.Msg == 0x200) //WM_MOUSEMOVE = 0x200 { HitTestInfo ht = TryHitTest(m); if (ht.Type == DataGridViewHitTestType.Cell) { if (lastHoveredCell != this[ht.ColumnIndex, ht.RowIndex]) { if (lastHoveredCell != null) { if (lastHoveredCell.RowIndex < RowCount && lastHoveredCell.ColumnIndex < ColumnCount && lastHoveredCell != this[lastHoveredCell.ColumnIndex, lastHoveredCell.RowIndex]) { lastHoveredCell = null; } else { InvalidateCell(lastHoveredCell); } } lastHoveredCell = this[ht.ColumnIndex, ht.RowIndex]; InvalidateCell(lastHoveredCell); } } } base.WndProc(ref m); }
protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e) { bDragging = false; HitTestInfo livehti = hti; hti = null; if (RowDropped != null && livehti != null && livehti.RowIndex != -1 && this.CurrentRow.Index != livehti.RowIndex) { RowDropped(this, this.CurrentRow, this.Rows[livehti.RowIndex]); } StopAutoScrolling(); Invalidate(); base.OnMouseUp(e); }
///<summary> ///Raises the <see cref="E:System.Windows.Forms.Control.MouseDown"></see> event. ///</summary> /// ///<param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs"></see> that contains the event data. </param> protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); HitTestInfo test = HitTest(e.Location); if (test != null && test.Area != HitTestArea.None) { if (test.Area == HitTestArea.Item && this[test.Index].IsLink) { Cursor = CursorHelper.PressedCursor; } else { Cursor = Cursors.Default; } } }
public override bool CanInsertActivities(HitTestInfo insertLocation, ReadOnlyCollection <Activity> activitiesToInsert) { int num = 0; foreach (Activity activity in ((EventHandlingScopeActivity)base.Activity).Activities) { if (!System.Workflow.Activities.Common.Helpers.IsFrameworkActivity(activity) && !(activity is EventHandlersActivity)) { num++; } } if (num > 0) { return(false); } return(base.CanInsertActivities(insertLocation, activitiesToInsert)); }
protected override void OnMouseMove( MouseEventArgs e) { if (_draggedPoint != null) { Rectangle gradientRect = GetGradientRect(); int p = Math.Min(gradientRect.Right, Math.Max(gradientRect.Left, e.X)) - gradientRect.Left; float newPosition = p / (float)gradientRect.Width; _draggedPoint.Position = newPosition; OnPointChanged(_draggedPoint); } else { HitTestInfo hti = HitTest(e.X, e.Y); HighlightedItem = hti.Point; } base.OnMouseMove(e); }
protected override void OnMouseDown(MouseEventArgs e) { if (e.Button == MouseButtons.Right) { HitTestInfo hti = HitTest(e.X, e.Y); if (hti.Type == DataGridViewHitTestType.Cell) { if (!((Rows[hti.RowIndex])).Selected) { ClearSelection(); (Rows[hti.RowIndex]).Selected = true; } } } base.OnMouseDown(e); }
/// <summary> /// Processes the "delete" key /// </summary> /// <param name="msg">message</param> /// <param name="keyData">key data</param> /// <returns>returns base.ProcessCmdKey</returns> protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (msg.Msg == WM_KEYDOWN) { if (keyData == Keys.Delete) { // finds the point on the client side. Point pt = this.PointToClient(Cursor.Position); // test the point HitTestInfo info = this.HitTest(pt); if (info.Type == HitTestType.RowHeader) { RemoveDeletedRowFromDataSource(info.Row); } } } return(base.ProcessCmdKey(ref msg, keyData)); }
public override AccessibleObject?HitTest(int x, int y) { if (!_ownerDataGridView.IsHandleCreated) { return(null); } Point pt = _ownerDataGridView.PointToClient(new Point(x, y)); HitTestInfo hti = _ownerDataGridView.HitTest(pt.X, pt.Y); switch (hti.Type) { case DataGridViewHitTestType.Cell: return(_ownerDataGridView.Rows[hti.RowIndex].Cells[hti.ColumnIndex].AccessibilityObject); case DataGridViewHitTestType.ColumnHeader: // map the column index to the actual display index int actualDisplayIndex = _ownerDataGridView.Columns.ColumnIndexToActualDisplayIndex(hti.ColumnIndex, DataGridViewElementStates.Visible); if (_ownerDataGridView.RowHeadersVisible) { // increment the childIndex because the first child in the TopRowAccessibleObject is the TopLeftHeaderCellAccObj return(TopRowAccessibilityObject.GetChild(actualDisplayIndex + 1)); } else { return(TopRowAccessibilityObject.GetChild(actualDisplayIndex)); } case DataGridViewHitTestType.RowHeader: return(_ownerDataGridView.Rows[hti.RowIndex].AccessibilityObject); case DataGridViewHitTestType.TopLeftHeader: return(_ownerDataGridView.TopLeftHeaderCell.AccessibilityObject); case DataGridViewHitTestType.VerticalScrollBar: return(_ownerDataGridView.VerticalScrollBar.AccessibilityObject); case DataGridViewHitTestType.HorizontalScrollBar: return(_ownerDataGridView.HorizontalScrollBar.AccessibilityObject); default: return(null); } }
public override HitTestInfo GetHitTestInfo(IGraphics gr, int x, int y, Point pt) { // caller will have tested if point is within bounding rect // taking into account additional ascent/descent on the line Debug.Assert(style != null, "No class attached to TextFragment!!"); string text = ProcessText(Text); gr.PushFont(gr.GetFontHandle(style.FontDesc)); try { BinaryChopper bc = new BinaryChopper(text); int w = 0; while (bc.CanMove) { // TODO: L: this could be optimised by calculating the shift // left and right in pixels rather than measuring from zero w = gr.MeasureText(bc.Text).Width; if (pt.X < x + w) { bc.TooLong(); } else { bc.TooShort(); } } int cw = gr.MeasureText(text[bc.Position].ToString()).Width; bool after = (float)1.0 * x + w - cw / 2 < pt.X; Debug.Assert(start + bc.Position < Node.Value.Length, "Invalid TextSelectionPoint!"); SelectionPoint sp = new TextSelectionPoint(Node, start + bc.Position); Line l = (Line)Parent; LineItemContext ili = new LineItemContext(l.Height, l.Baseline, this, new Point(x, y)); HitTestInfo ht = new HitTestInfo(sp, ili, after); return(ht); } finally { gr.PopFont(); } }
/// <summary> /// Adds a new connection. /// </summary> /// <param name="connection">The connection.</param> private void AddConnection(TileConnection connection) { ConnectableViewItem connectableFrom = this.GetConnectable(connection.FromId); if (connectableFrom == null) { return; } ConnectableViewItem connectableTo = this.GetConnectable(connection.ToId); if (connectableTo == null) { return; } //From HitTestInfo hitTestInfo = this.GetHitTestInfo(connection.FromOrientation); ConnectorInfo originConnectorInfo = connectableFrom.CreateDiagramConnection(hitTestInfo); DiagramConnection newConnection = new DiagramConnection(connectableFrom, originConnectorInfo, 0) { Id = connection.Id, ConnectionType = connection.ConnectionType, RoutingMode = connection.RoutingMode }; newConnection.EditOperationRequested += this.OnConnectionEditRequested; //newConnection.CreateConnection(connection.Color, this.scatterView.DiagramSelectedConnectionColor, this.scatterView.DiagramConnectionHighlightColor, connection.Thickness, connection.Opacity); //To hitTestInfo = this.GetHitTestInfo(connection.ToOrientation); ConnectorInfo targetConnectorInfo = connectableTo.CreateDiagramConnection(hitTestInfo); //newConnection.CompletePendingConnection(connectableTo, targetConnectorInfo, this.scatterView.ControlTileScale); //Adds connection to related tiles newConnection.Origin.DiagramConnections.Add(newConnection); newConnection.Destination.DiagramConnections.Add(newConnection); connection.DiagramConnection = newConnection; //this.scatterView.AddVisualConnection(newConnection, false); }
/// <summary> /// Displayes context menu for a grid /// </summary> protected void OnContextMenuShow(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { HitTestInfo hitTest = this.HitTest(e.X, e.Y); if (hitTest != null && hitTest.Type == DataGridViewHitTestType.Cell && hitTest.RowIndex >= 0 && hitTest.ColumnIndex >= 0) { // was clicked on one of selected rows? bool isRowSelected = Rows[hitTest.RowIndex].Selected; if (!isRowSelected) // no - clear selection and make the clicked row selected { this.ClearSelection(); Rows[hitTest.RowIndex].Selected = true; } this.ContextMenu.Show(this, e.Location); // display context menu } } }
public CellContent GetCellContentFromPoint(int x, int y) { HitTestInfo hit = HitTest(x, y); if (hit.Type == DataGridViewHitTestType.Cell) { DataGridViewCellValueEventArgs args = new DataGridViewCellValueEventArgs(hit.ColumnIndex, hit.RowIndex); OnCellValueNeeded(args); for (int i = 0; i < this.ColumnCount; ++i) { Rectangle r = this.GetColumnDisplayRectangle(i, false); if (x > r.Left && x < r.Right) { return(new CellContent(args.Value as string, r.Left)); } } } return(null); }
// expand/collapse child grid // // if the user clicks the icons (drawn in the method above), either // create a child grid (and bind it to the detail records), or remove // the existing one. // override protected void OnBeforeMouseDown(BeforeMouseDownEventArgs e) { // always call base implementation base.OnBeforeMouseDown(e); // check that it's the Left button and that we have a hierarchy if (e.Button != MouseButtons.Left || _colChild == null) { return; } // check that it's a row header cell HitTestInfo hit = HitTest(e.X, e.Y); if (hit.Type != HitTestTypeEnum.RowHeader || hit.Row < Rows.Fixed) { return; } // check that the click was over the collapse/expand icon if (e.X < Cols[0].Right - (Glyphs[GlyphEnum.Collapsed].Width + 4)) { return; } // if the row has no children and the user can't add new, cancel <<B2>> IList list = _colChild[hit.Row] as IList; if (list == null || list.Count == 0) { if (!AllowAddNew) { return; } } // all checks OK, cancel click before proceeding e.Cancel = true; Select(hit.Row, Cols.Fixed, hit.Row, Cols.Count - 1, false); // toggle row state ToggleRowState(hit.Row); }
private void InParametersDataGridView_DragDrop(object sender, DragEventArgs e) { dragedBranch = (IBranch)e.Data.GetData(e.Data.GetFormats()[0]); Point p = inParametersDataGridView.PointToClient(new Point(e.X, e.Y)); PassedArgs inpar = new PassedArgs(); HitTestInfo myHitTest = inParametersDataGridView.HitTest(p.X, p.Y); if (myHitTest.RowIndex == -1) { // this.inTableParametersBindingSource.AddNew(); inpar = (PassedArgs)this.inTableParametersBindingSource.Current; } else { if (myHitTest.RowIndex == this.inTableParametersBindingSource.Count) { this.inTableParametersBindingSource.AddNew(); inpar = (PassedArgs)this.inTableParametersBindingSource.Current; } else { inpar = (PassedArgs)this.inParametersDataGridView.Rows[myHitTest.RowIndex].DataBoundItem; // } } if (this.inTableParametersBindingSource.Count <= 1) { this.inTableParametersBindingSource.AddNew(); inpar = (PassedArgs)this.inTableParametersBindingSource.Current; } if (this.inTableParametersBindingSource.Current == null) { this.inTableParametersBindingSource.AddNew(); inpar = (PassedArgs)this.inTableParametersBindingSource.Current; } inpar.Category = dragedBranch.BranchClass; inpar.CurrentEntity = dragedBranch.BranchText; inpar.DatasourceName = dragedBranch.DataSourceName; inpar.EventType = dragedBranch.BranchType.ToString(); this.inParametersDataGridView.Refresh(); }
/// <summary> /// Determine if an activity can be added /// </summary> /// <param name="insertLocation"></param> /// <param name="activitiesToInsert"></param> /// <returns></returns> public override bool CanInsertActivities(HitTestInfo insertLocation, ReadOnlyCollection <Activity> activitiesToInsert) { //allow only selected activity types Boolean result = true; if (activitiesToInsert != null) { foreach (Activity activity in activitiesToInsert) { result = (_allowedActivityTypes.Contains(activity.GetType())); if (result == false) { break; } } } return(result); }
public override bool CanInsertActivities(HitTestInfo insertLocation, System.Collections.ObjectModel.ReadOnlyCollection <Activity> activitiesToInsert) { //we only allow one activity to be inserted int childCount = 0; foreach (Activity child in ((EventHandlingScopeActivity)this.Activity).Activities) { if (!Helpers.IsFrameworkActivity(child) && !(child is EventHandlersActivity)) { childCount++; } } if (childCount > 0) { return(false); } return(base.CanInsertActivities(insertLocation, activitiesToInsert)); }
/// <summary> /// Maps a HitTestInfo to a ConnectorOrientation /// </summary> /// <param name="hitTestInfo">The hit test information.</param> /// <returns>Mapped value</returns> public static ConnectorOrientation ToConnectorOrientation(this HitTestInfo hitTestInfo) { switch (hitTestInfo) { case HitTestInfo.AnchorLeft: return(ConnectorOrientation.Left); case HitTestInfo.AnchorTop: return(ConnectorOrientation.Top); case HitTestInfo.AnchorRight: return(ConnectorOrientation.Right); case HitTestInfo.AnchorBottom: return(ConnectorOrientation.Bottom); default: return(ConnectorOrientation.None); } }
/// <summary> /// Performs the HitTest. /// </summary> /// <param name="p">Point at which HitTest will be performed.</param> /// <returns>returm <see cref="HitTestInfo"/> object containing HitTest information.</returns> public HitTestInfo HitTest(Point p) { HitTestInfo info = new HitTestInfo(); info.Area = HitTestArea.None; info.Point = p; info.Index = -1; for (int i = firstIndex; i < elements.Count; i++) { if (elements[i].TextRect.Contains(p)) { info.Area = HitTestArea.Item; info.Index = i; break; } else if (elements[i].LeftRect.Contains(p)) { info.Area = HitTestArea.LeftImage; info.Index = i; break; } else if (elements[i].RightRect.Contains(p)) { info.Area = HitTestArea.RightImage; info.Index = i; break; } } if (info.Area == HitTestArea.None) { if (bound.Contains(p)) { info.Area = HitTestArea.Strip; } else if (ClientRectangle.Contains(p)) { info.Area = HitTestArea.Control; } } return(info); }
protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e) { List <DataGridViewCell> selectedCells = null; // Intercept left clicks without modifier keys. if (AllowMultiRowDrag && (e.Button & MouseButtons.Left) == MouseButtons.Left && ModifierKeys == Keys.None) { HitTestInfo hitInfo = HitTest(e.X, e.Y); // If the empty space is clicked then clean the selection. if (hitInfo.Type == DataGridViewHitTestType.None) { ClearSelection(); } // If a selected cell is clicked, remember the current selection // and temporary suspend the control redrawing. else if (hitInfo.Type == DataGridViewHitTestType.Cell && this[hitInfo.ColumnIndex, hitInfo.RowIndex].Selected) { selectedCells = SelectedCells.OfType <DataGridViewCell>().ToList(); holdedCellToSelect = this[hitInfo.ColumnIndex, hitInfo.RowIndex]; SendMessage(this.Handle, WM_SETREDRAW, false, 0); } } // Perform base processing. base.OnMouseDown(e); // Restore selection if necessary and resume the control redrawing. if (holdedCellToSelect != null) { ClearSelection(); foreach (var cell in selectedCells) { cell.Selected = true; } SendMessage(this.Handle, WM_SETREDRAW, true, 0); } }
/// <summary> /// OnMouseDown /// </summary> /// <remarks> /// if the RowHeader hitted - unselect previouslySelectedDataGridRow and selects the new one. /// </remarks> /// <param name="e"></param> protected override void OnMouseDown(MouseEventArgs e) { // finds the point on the client side. HitTestInfo info = this.HitTest(e.X, e.Y); if (info.Type == HitTestType.RowHeader) { if (selectedDataGridRow != -1) { this.UnSelect(selectedDataGridRow); } selectedDataGridRow = info.Row; this.Select(selectedDataGridRow); } else { base.OnMouseDown(e); } }
protected override void OnMouseDown(MouseEventArgs e) { if ((e.Button & MouseButtons.Left) == MouseButtons.Left) { this.UpdateFocusedDayPosition(e.Location); HitTestInfo hti = this.HitTest(e.Location); if (hti.Type == HitTestType.Glyph1) { if (this.RightToLeft != RightToLeft.Yes) { this.PrevMonth(); } else { this.NextMonth(); } } else if (hti.Type == HitTestType.Glyph2) { if (this.RightToLeft != RightToLeft.Yes) { this.NextMonth(); } else { this.PrevMonth(); } } else if (hti.Type == HitTestType.Footer) { var selectedDate = DateTime.Now; this.ValueInternal = selectedDate; if (this.ValueInternal.Date.Equals(selectedDate.Date)) { this.OnDateSelected(); } } } base.OnMouseDown(e); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.MouseUp"></see> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs"></see> that /// contains the event data.</param> /// ------------------------------------------------------------------------------------ protected override void OnMouseUp(MouseEventArgs e) { HitTestInfo info = HitTest(e.X, e.Y); if (info.Type == DataGridViewHitTestType.Cell) { DataGridViewControlColumn column = Columns[info.ColumnIndex] as DataGridViewControlColumn; column.StandardWidth = column.Width; if (e.X < column.ThresholdWidth && e.X > DataGridViewControlColumn.kMinimumValue) { e = new MouseEventArgs(e.Button, e.Clicks, column.ThresholdWidth, e.Y, e.Delta); } } base.OnMouseUp(e); // Hide all the rows and columns that are to small now foreach (DataGridViewBand band in m_ColumnsAndRowsToHide) { band.Visible = false; } m_ColumnsAndRowsToHide.Clear(); for (int iColumn = 0; iColumn < ColumnCount; iColumn++) { DataGridViewControlColumn col = Columns[iColumn] as DataGridViewControlColumn; // The current column can occupy a maximum percentage of the remaining width // (calculated as width from the left edge of the column to the right edge of // the grid) - except the last column which can occupy max percentage of the // entire width. Rectangle colRect = GetColumnDisplayRectangle(iColumn, false); int remainingWidth = (iColumn == ColumnCount - 1) ? Width : Width - colRect.Left; if (col.MaxPercentage > 0 && col.MaxPercentage < (float)col.Width / (float)remainingWidth) { col.Width = (int)(col.MaxPercentage * remainingWidth); } } }
private void gridRoteiros_BeforeMouseDown(object sender, BeforeMouseDownEventArgs e) { if (e.Clicks > 1) { return; } //start dragging when the user clicks the cell C1FlexGrid flex = (C1FlexGrid)sender; HitTestInfo hti = flex.HitTest(e.X, e.Y); if (hti.Type == HitTestTypeEnum.Cell) { //select the row int index = hti.Row; if (index != 0) { flex.Select(index, 0, index, flex.Cols.Count - 1, false); ////save info for target //_src = flex; //do drag drop DragDropEffects dd = flex.DoDragDrop(flex.Clip, DragDropEffects.Move); //if it worked, delete row from source (it's a move) if (dd == DragDropEffects.Move) { //flex.Rows.Remove(index); //colunaOrdenacao = SEM_ORDENACAO; //LimparGridRoteiros(); //PopulaRoteirosGrid(fachada.CarregarRoteiros(controladorSelecionado, painelSelecionado)); //gridRoteiros.Select() } ////done, reset info //_src = null; } } }
protected override void OnCellMouseUp(DataGridViewCellMouseEventArgs e) { if (((e.Button == MouseButtons.Left)) && ((e.ColumnIndex == 0) && (e.RowIndex >= 0))) { Point location = base.GetCellDisplayRectangle(0, e.RowIndex, false).Location; location.Offset(e.Location); HitTestInfo hitInfo = base.HitTest(location.X, location.Y); if (hitInfo.ColumnIndex != 0) { return; } DataGridViewCell cell = base.Rows[e.RowIndex].Cells[0]; if (e.X < cell.Style.Padding.Left) { IDtsGridRowData ganttRowData = ((BindingSource)this.DataSource)[e.RowIndex] as IDtsGridRowData; if (ganttRowData != null && ganttRowData.HasChildren) { base.EndEdit(); if ((e.X >= ((cell.Style.Padding.Left - BIDSHelper.Resources.Common.Package.Width) - INDENTATION_WIDTH)) && (e.X < (cell.Style.Padding.Left - BIDSHelper.Resources.Common.Package.Width))) { this.SetIsExpanded(e.RowIndex, !this.GetIsExpanded(e.RowIndex)); //this.InvokePaint(this, new PaintEventArgs(this.CreateGraphics(), this.GetColumnDisplayRectangle(1, false))); //don't think this is necessary } } } } else if (e.Button == MouseButtons.Right && e.ColumnIndex == 0 && e.RowIndex >= 0) { IDtsGridRowData rowData = ((BindingSource)this.DataSource)[e.RowIndex] as IDtsGridRowData; if (rowData is DtsPipelinePerformance && this.ParentPerformanceTab != null) { Rectangle rect = this.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true); this._ContextMenuDataFlowTaskID = (rowData as DtsPipelinePerformance).ID; this.contextMenuBreakdown.Show(this, new Point(e.X, rect.Y + e.Y)); } } base.OnCellMouseUp(e); }
private bool GetOutOfBoundCorrectedHitTestInfo(ref HitTestInfo hti, ref int mouseX, ref int mouseY, out int xOffset, out int yOffset) { xOffset = yOffset = 0; Rectangle rectScrollingArea = this.layout.Data; int visibleRowsHeight = this.Rows.GetRowsHeight(DataGridViewElementStates.Visible); int frozenVisibleRowsHeight = this.Rows.GetRowsHeight(DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen); int fittingTrailingScrollingRowsHeight = ComputeHeightOfFittingTrailingScrollingRows(frozenVisibleRowsHeight); int trailingScrollingRowsHeight = ComputeHeightOfTrailingScrollingRows(); int emptyBackgroundWidth = Math.Max(0, this.layout.Data.Width - this.Columns.GetColumnsWidth(DataGridViewElementStates.Visible)); int emptyBackgroundHeight = Math.Max(0, this.layout.Data.Height - frozenVisibleRowsHeight - trailingScrollingRowsHeight); Debug.Assert(!this.vertScrollBar.Enabled || !this.vertScrollBar.Visible || this.vertScrollBar.Maximum == visibleRowsHeight - frozenVisibleRowsHeight); //VSWhidbey 525671 //Debug.Assert(!this.vertScrollBar.Enabled || // !this.vertScrollBar.Visible || // this.vertScrollBar.Value >= this.verticalOffset); if (this.dataGridViewOper[DATAGRIDVIEWOPER_trackRowSelect]) { if (this.layout.RowHeadersVisible) { // Include row headers rectScrollingArea = Rectangle.Union(rectScrollingArea, this.layout.RowHeaders); } // Discard frozen rows DiscardZonesInScrollingArea(ref rectScrollingArea, emptyBackgroundWidth, emptyBackgroundHeight, frozenVisibleRowsHeight, false /*discardFrozenColumns*/, true /*discardFrozenRows*/); if (mouseY >= rectScrollingArea.Top && mouseY <= rectScrollingArea.Bottom) { // Mouse's Y is in-bound -- correct X value hti = HitTest(this.RightToLeftInternal ? rectScrollingArea.Right-1 : rectScrollingArea.Left, mouseY); if (this.ptAnchorCell.Y != -1 && (this.Rows.GetRowState(this.ptAnchorCell.Y) & DataGridViewElementStates.Frozen) != 0 && this.trackRowEdge != -1 && (this.Rows.GetRowState(this.trackRowEdge) & DataGridViewElementStates.Frozen) != 0 && hti.row >= 0 && (this.Rows.GetRowState(hti.row) & DataGridViewElementStates.Frozen) == 0) { // Anchor cell is in frozen row and target cell is in unfrozen row. Make sure no row is scrolled off. Debug.Assert(this.displayedBandsInfo.FirstDisplayedScrollingRow >= 0); int firstUnfrozenRowIndex = this.Rows.GetFirstRow(DataGridViewElementStates.Visible, DataGridViewElementStates.Frozen); int firstColumnIndex; if (hti.col >= 0) { firstColumnIndex = hti.col; } else { DataGridViewColumn dataGridViewColumn = this.Columns.GetFirstColumn(DataGridViewElementStates.Visible); firstColumnIndex = (dataGridViewColumn == null) ? -1 : dataGridViewColumn.Index; } if (firstColumnIndex >= 0 && firstUnfrozenRowIndex >= 0) { if (!ScrollIntoView(firstColumnIndex, firstUnfrozenRowIndex, false /*forCurrentCellChange*/)) { return false; } hti = HitTest(this.RightToLeftInternal ? rectScrollingArea.Right : rectScrollingArea.Left, mouseY); } } return true; } // Mouse's Y is outside of scrolling bands if (mouseY < rectScrollingArea.Top) { if (this.ptAnchorCell.Y != -1 && ((this.Rows.GetRowState(this.ptAnchorCell.Y) & DataGridViewElementStates.Frozen) == 0 || (this.trackRowEdge != -1 && (this.Rows.GetRowState(this.trackRowEdge) & DataGridViewElementStates.Frozen) == 0)) && this.verticalOffset != 0) { // Up scrolling is required because the anchor's row is unfrozen Debug.Assert(this.displayedBandsInfo.FirstDisplayedScrollingRow >= 0); yOffset = mouseY - rectScrollingArea.Top; // yOffset strictly negative if (this.RightToLeftInternal) { mouseX = rectScrollingArea.Right-1; } else { mouseX = rectScrollingArea.Left+1; } } else { hti = HitTest(this.RightToLeftInternal ? rectScrollingArea.Right : rectScrollingArea.Left, mouseY); } } else { Debug.Assert(mouseY > rectScrollingArea.Bottom); if (this.displayedBandsInfo.FirstDisplayedScrollingRow >= 0) { if (this.verticalOffset + this.Rows.SharedRow(this.displayedBandsInfo.FirstDisplayedScrollingRow).GetHeight(this.displayedBandsInfo.FirstDisplayedScrollingRow) <= visibleRowsHeight - frozenVisibleRowsHeight - fittingTrailingScrollingRowsHeight) { // Down scrolling is required yOffset = mouseY - rectScrollingArea.Bottom; // yOffset strictly positive if (this.RightToLeftInternal) { mouseX = rectScrollingArea.Right-1; } else { mouseX = rectScrollingArea.Left+1; } } } } return true; } if (this.dataGridViewOper[DATAGRIDVIEWOPER_trackColSelect]) { if (this.layout.ColumnHeadersVisible) { // Include column headers rectScrollingArea = Rectangle.Union(rectScrollingArea, this.layout.ColumnHeaders); } // Discard frozen columns DiscardZonesInScrollingArea(ref rectScrollingArea, emptyBackgroundWidth, emptyBackgroundHeight, frozenVisibleRowsHeight, true /*discardFrozenColumns*/, false /*discardFrozenRows*/); if (mouseX >= rectScrollingArea.Left && mouseX <= rectScrollingArea.Right) { // Mouse's X is in-bound -- correct Y value hti = HitTest(mouseX, rectScrollingArea.Top); if (this.ptAnchorCell.X != -1 && this.Columns[this.ptAnchorCell.X].Frozen && this.trackColumnEdge != -1 && this.Columns[this.trackColumnEdge].Frozen && hti.col >= 0 && !this.Columns[hti.col].Frozen) { // Anchor cell is in frozen column and target cell is in unfrozen column. Make sure no column is scrolled off. Debug.Assert(this.displayedBandsInfo.FirstDisplayedScrollingCol >= 0); int firstUnfrozenColumnIndex = this.Columns.GetFirstColumn(DataGridViewElementStates.Visible, DataGridViewElementStates.Frozen).Index; int firstRowIndex; if (hti.row >= 0) { firstRowIndex = hti.row; } else { firstRowIndex = this.Rows.GetFirstRow(DataGridViewElementStates.Visible); } if (firstRowIndex >= 0 && firstUnfrozenColumnIndex >= 0) { if (!ScrollIntoView(firstUnfrozenColumnIndex, firstRowIndex, false /*forCurrentCellChange*/)) { return false; } hti = HitTest(mouseX, rectScrollingArea.Top); } } return true; } // Mouse's X is outside of scrolling bands if ((!this.RightToLeftInternal && mouseX < rectScrollingArea.Left) || (this.RightToLeftInternal && mouseX > rectScrollingArea.Right)) { if (this.ptAnchorCell.X != -1 && (!this.Columns[this.ptAnchorCell.X].Frozen || (this.trackColumnEdge != -1 && !this.Columns[this.trackColumnEdge].Frozen)) && this.displayedBandsInfo.FirstDisplayedScrollingCol >= 0 && (this.negOffset > 0 || this.Columns.GetPreviousColumn(this.Columns[this.displayedBandsInfo.FirstDisplayedScrollingCol], DataGridViewElementStates.Visible, DataGridViewElementStates.Frozen) != null)) { // xOffset strictly negative if (this.RightToLeftInternal) { // Right scrolling is required xOffset = rectScrollingArea.Right - mouseX; } else { // Left scrolling is required xOffset = mouseX - rectScrollingArea.Left; } mouseY = rectScrollingArea.Top+1; } else { hti = HitTest(mouseX, rectScrollingArea.Top); } } else { Debug.Assert((!this.RightToLeftInternal && mouseX > rectScrollingArea.Right) || (this.RightToLeftInternal && mouseX < rectScrollingArea.Left)); if (this.displayedBandsInfo.FirstDisplayedScrollingCol >= 0) { if (this.displayedBandsInfo.LastTotallyDisplayedScrollingCol != -1 && this.Columns.GetNextColumn(this.Columns[this.displayedBandsInfo.LastTotallyDisplayedScrollingCol], DataGridViewElementStates.Visible, DataGridViewElementStates.None) == null) { // No more columns to scroll return true; } DataGridViewColumn newFirstVisibleScrollingCol = this.Columns.GetNextColumn(this.Columns[this.displayedBandsInfo.FirstDisplayedScrollingCol], DataGridViewElementStates.Visible, DataGridViewElementStates.None); int newColOffset = 0; for (DataGridViewColumn dataGridViewColumn = this.Columns.GetFirstColumn(DataGridViewElementStates.Visible, DataGridViewElementStates.Frozen); dataGridViewColumn != newFirstVisibleScrollingCol; dataGridViewColumn = this.Columns.GetNextColumn(dataGridViewColumn, DataGridViewElementStates.Visible, DataGridViewElementStates.None)) { newColOffset += dataGridViewColumn.Thickness; } if (this.HorizontalOffset != newColOffset) { // xOffset strictly positive if (this.RightToLeftInternal) { // Left scrolling is required xOffset = rectScrollingArea.Left - mouseX; } else { // Right scrolling is required xOffset = mouseX - rectScrollingArea.Right; } mouseY = rectScrollingArea.Top+1; } } } return true; } if (this.dataGridViewOper[DATAGRIDVIEWOPER_trackCellSelect]) { bool recomputeHitTestInfo = false; // Discard frozen columns and rows DiscardZonesInScrollingArea(ref rectScrollingArea, emptyBackgroundWidth, emptyBackgroundHeight, frozenVisibleRowsHeight, true /*discardFrozenColumns*/, true /*discardFrozenRows*/); if (mouseY < rectScrollingArea.Top) { // Mouse's Y is above scrolling bands if ( ( (this.ptAnchorCell.Y != -1 && (this.Rows.GetRowState(this.ptAnchorCell.Y) & DataGridViewElementStates.Frozen) == 0) || (this.ptCurrentCell.Y != -1 && (this.Rows.GetRowState(this.ptCurrentCell.Y) & DataGridViewElementStates.Frozen) == 0) ) && this.verticalOffset != 0 ) { // Up scrolling is required - the anchor's row is unfrozen Debug.Assert(this.displayedBandsInfo.FirstDisplayedScrollingRow >= 0); yOffset = mouseY - rectScrollingArea.Top; // yOffset strictly negative } else { // Correct mouse's Y - no scrolling can be performed if (mouseY < this.layout.Data.Top) { mouseY = this.layout.Data.Top+1; recomputeHitTestInfo = true; } } } else if (mouseY > rectScrollingArea.Bottom) { // Mouse's Y is below scrolling bands if (this.displayedBandsInfo.FirstDisplayedScrollingRow >= 0) { if (this.verticalOffset + this.Rows.SharedRow(this.displayedBandsInfo.FirstDisplayedScrollingRow).GetHeight(this.displayedBandsInfo.FirstDisplayedScrollingRow) <= visibleRowsHeight - frozenVisibleRowsHeight - fittingTrailingScrollingRowsHeight) { // Down scrolling is required yOffset = mouseY - rectScrollingArea.Bottom; // yOffset strictly positive } else { // Correct mouse's Y - no scrolling can be performed mouseY = rectScrollingArea.Bottom-1; recomputeHitTestInfo = true; } } else { // Correct mouse's Y - no scrolling can be performed mouseY = rectScrollingArea.Bottom-1; recomputeHitTestInfo = true; } } #if DEBUG else { // Mouse's Y is in-bound Debug.Assert(mouseY >= rectScrollingArea.Top && mouseY <= rectScrollingArea.Bottom); } #endif if ((!this.RightToLeftInternal && mouseX < rectScrollingArea.Left) || (this.RightToLeftInternal && mouseX > rectScrollingArea.Right)) { // Mouse's X is on the left of scrolling bands (LTR) if ( ( (this.ptAnchorCell.X != -1 && !this.Columns[this.ptAnchorCell.X].Frozen) || (this.ptCurrentCell.X != -1 && !this.Columns[this.ptCurrentCell.X].Frozen) ) && this.displayedBandsInfo.FirstDisplayedScrollingCol >= 0 && (this.negOffset > 0 || this.Columns.GetPreviousColumn(this.Columns[this.displayedBandsInfo.FirstDisplayedScrollingCol], DataGridViewElementStates.Visible, DataGridViewElementStates.Frozen) != null) ) { // xOffset strictly negative if (this.RightToLeftInternal) { // Right scrolling is required - anchor's column is unfrozen xOffset = rectScrollingArea.Right - mouseX; } else { // Left scrolling is required - anchor's column is unfrozen xOffset = mouseX - rectScrollingArea.Left; } } else { // Correct mouse's X - no scrolling can be performed if (!this.RightToLeftInternal && mouseX < this.layout.Data.Left) { mouseX = this.layout.Data.Left+1; recomputeHitTestInfo = true; } else if (this.RightToLeftInternal && mouseX > this.layout.Data.Right) { mouseX = this.layout.Data.Right-1; recomputeHitTestInfo = true; } } } else if ((!this.RightToLeftInternal && mouseX > rectScrollingArea.Right) || (this.RightToLeftInternal && mouseX < rectScrollingArea.Left)) { // Mouse's X is on the right of scrolling bands (LTR) if (this.displayedBandsInfo.FirstDisplayedScrollingCol >= 0 && (this.displayedBandsInfo.LastTotallyDisplayedScrollingCol == -1 || this.Columns.GetNextColumn(this.Columns[this.displayedBandsInfo.LastTotallyDisplayedScrollingCol], DataGridViewElementStates.Visible, DataGridViewElementStates.None) != null)) { DataGridViewColumn newFirstVisibleScrollingCol = this.Columns.GetNextColumn(this.Columns[this.displayedBandsInfo.FirstDisplayedScrollingCol], DataGridViewElementStates.Visible, DataGridViewElementStates.None); int newColOffset = 0; for (DataGridViewColumn dataGridViewColumn = this.Columns.GetFirstColumn(DataGridViewElementStates.Visible, DataGridViewElementStates.Frozen); dataGridViewColumn != newFirstVisibleScrollingCol; dataGridViewColumn = this.Columns.GetNextColumn(dataGridViewColumn, DataGridViewElementStates.Visible, DataGridViewElementStates.None)) { newColOffset += dataGridViewColumn.Thickness; } if (this.HorizontalOffset != newColOffset) { // xOffset strictly positive if (this.RightToLeftInternal) { // Left scrolling is required xOffset = rectScrollingArea.Left - mouseX; } else { // Right scrolling is required xOffset = mouseX - rectScrollingArea.Right; } } else { // Correct mouse's X - no scrolling can be performed if (this.RightToLeftInternal) { mouseX = rectScrollingArea.Left+1; } else { mouseX = rectScrollingArea.Right-1; } recomputeHitTestInfo = true; } } else { // Correct mouse's X - no scrolling can be performed if (this.RightToLeftInternal) { mouseX = rectScrollingArea.Left+1; } else { mouseX = rectScrollingArea.Right-1; } recomputeHitTestInfo = true; } } #if DEBUG else { // Mouse's X is in-bound Debug.Assert(mouseX >= rectScrollingArea.Left && mouseX <= rectScrollingArea.Right); } #endif if (recomputeHitTestInfo) { hti = HitTest(mouseX, mouseY); } } return true; }
public HitTestInfo HitTest(int x, int y) { int num1 = this.layout.Data.Y; HitTestInfo info = new HitTestInfo(); if (this.layout.CaptionVisible && this.layout.Caption.Contains(x, y)) { info.type = HitTestType.Caption; return info; } if (this.layout.ParentRowsVisible && this.layout.ParentRows.Contains(x, y)) { info.type = HitTestType.ParentRows; return info; } if (!this.layout.Inside.Contains(x, y)) { return info; } if (this.layout.TopLeftHeader.Contains(x, y)) { return info; } if (this.layout.ColumnHeaders.Contains(x, y)) { info.type = HitTestType.ColumnHeader; info.col = this.GetColFromX(x); if (info.col < 0) { return HitTestInfo.Nowhere; } int colBeg = this.GetColBeg(info.col + 1); bool flag = this.isRightToLeft(); if ((flag && ((x - colBeg) < 8)) || (!flag && ((colBeg - x) < 8))) { info.type = HitTestType.ColumnResize; } if (!this.allowColumnResize) { return HitTestInfo.Nowhere; } return info; } if (this.layout.RowHeaders.Contains(x, y)) { info.type = HitTestType.RowHeader; info.row = this.GetRowFromY(y); if (info.row < 0) { return HitTestInfo.Nowhere; } DataGridRow[] dataGridRows = this.DataGridRows; int num2 = this.GetRowTop(info.row) + dataGridRows[info.row].Height; if ((((num2 - y) - this.BorderWidth) < 2) && !(dataGridRows[info.row] is DataGridAddNewRow)) { info.type = HitTestType.RowResize; } if (!this.allowRowResize) { return HitTestInfo.Nowhere; } return info; } if (!this.layout.Data.Contains(x, y)) { return info; } info.type = HitTestType.Cell; info.col = this.GetColFromX(x); info.row = this.GetRowFromY(y); if ((info.col >= 0) && (info.row >= 0)) { return info; } return HitTestInfo.Nowhere; }
public override HitTestInfo GetHitTestInfo(IGraphics gr, int x, int y, Point pt) { // caller will have tested if point is within bounding rect // taking into account additional ascent/descent on the line Debug.Assert(style != null, "No class attached to TextFragment!!"); string text=ProcessText(Text); gr.PushFont(gr.GetFontHandle(style.FontDesc)); try { BinaryChopper bc=new BinaryChopper(text); int w=0; while ( bc.CanMove ) { // TODO: L: this could be optimised by calculating the shift // left and right in pixels rather than measuring from zero w=gr.MeasureText(bc.Text).Width; if ( pt.X < x+w ) bc.TooLong(); else bc.TooShort(); } int cw=gr.MeasureText(text[bc.Position].ToString()).Width; bool after=(float) 1.0 * x + w - cw / 2 < pt.X; Debug.Assert(start+bc.Position < Node.Value.Length, "Invalid TextSelectionPoint!"); SelectionPoint sp=new TextSelectionPoint(Node, start+bc.Position); Line l=(Line) Parent; LineItemContext ili=new LineItemContext(l.Height, l.Baseline, this, new Point(x,y)); HitTestInfo ht=new HitTestInfo(sp, ili, after); return ht; } finally { gr.PopFont(); } }
// selects one of the buttons private void DoButtonMouseDown (HitTestInfo hti) { // show the click then move on SetItemClick(hti); if (hti.HitArea == HitArea.PrevMonthButton) { // invalidate the prev monthbutton this.Invalidate( new Rectangle ( this.ClientRectangle.X + 1 + button_x_offset, this.ClientRectangle.Y + 1 + (title_size.Height - button_size.Height)/2, button_size.Width, button_size.Height)); int scroll = (scroll_change == 0 ? CalendarDimensions.Width * CalendarDimensions.Height : scroll_change); this.CurrentMonth = this.CurrentMonth.AddMonths (-scroll); } else { // invalidate the next monthbutton this.Invalidate( new Rectangle ( this.ClientRectangle.Right - 1 - button_x_offset - button_size.Width, this.ClientRectangle.Y + 1 + (title_size.Height - button_size.Height)/2, button_size.Width, button_size.Height)); int scroll = (scroll_change == 0 ? CalendarDimensions.Width * CalendarDimensions.Height : scroll_change); this.CurrentMonth = this.CurrentMonth.AddMonths (scroll); } }
private void DoSelectionOnMouseDown (HitTestInfo hitTest) { Keys modifiers = Control.ModifierKeys; bool isControl = (modifiers & Keys.Control) != 0; bool isShift = (modifiers & Keys.Shift) != 0; //bool isRowHeader = hitTest.Type == DataGridViewHitTestType.RowHeader; //bool isColHeader = hitTest.Type == DataGridViewHitTestType.ColumnHeader; DataGridViewSelectionMode mode; switch (hitTest.Type) { case DataGridViewHitTestType.Cell: mode = selectionMode; break; case DataGridViewHitTestType.ColumnHeader: mode = selectionMode == DataGridViewSelectionMode.ColumnHeaderSelect ? DataGridViewSelectionMode.FullColumnSelect : selectionMode; if (mode != DataGridViewSelectionMode.FullColumnSelect) return; break; case DataGridViewHitTestType.RowHeader: mode = selectionMode == DataGridViewSelectionMode.RowHeaderSelect ? DataGridViewSelectionMode.FullRowSelect : selectionMode; if (mode != DataGridViewSelectionMode.FullRowSelect) return; break; // Handled below default: return; } if (!isControl) { // If SHIFT is pressed: // Select all from selected_row/column/cell to current row/column/cell, unselect everything else // otherwise: // Unselect all rows/columns/cells, select the clicked one int min_row, max_row; int min_col, max_col; if (!isShift) { selected_row = hitTest.RowIndex; selected_column = hitTest.ColumnIndex; } if (!isShift) { if (selected_row != -1) selected_row = hitTest.RowIndex; if (selected_column != -1) selected_column = hitTest.ColumnIndex; } if (selected_row >= hitTest.RowIndex) { min_row = hitTest.RowIndex; max_row = isShift ? selected_row : min_row; } else { max_row = hitTest.RowIndex; min_row = isShift ? selected_row : max_row; } if (selected_column >= hitTest.ColumnIndex) { min_col = hitTest.ColumnIndex; max_col = isShift ? selected_column : min_col; } else { max_col = hitTest.ColumnIndex; min_col = isShift ? selected_column : max_col; } switch (mode) { case DataGridViewSelectionMode.FullRowSelect: for (int i = 0; i < RowCount; i++) { bool select = i >= min_row && i <= max_row; if (!select) { for (int c = 0; c < ColumnCount; c++) { if (Rows [i].Cells [c].Selected) { SetSelectedCellCore (c, i, false); } } } if (select != Rows [i].Selected) { SetSelectedRowCore (i, select); } } break; case DataGridViewSelectionMode.FullColumnSelect: for (int i = 0; i < ColumnCount; i++) { bool select = i >= min_col && i <= max_col; if (!select) { for (int r = 0; r < RowCount; r++) { if (Rows [r].Cells [i].Selected) { SetSelectedCellCore (i, r, false); } } } if (select != Columns [i].Selected) { SetSelectedColumnCore (i, select); } } break; case DataGridViewSelectionMode.ColumnHeaderSelect: case DataGridViewSelectionMode.RowHeaderSelect: //break; case DataGridViewSelectionMode.CellSelect: if (!isShift) { for (int c = 0; c < ColumnCount; c++) { if (columns [c].Selected) SetSelectedColumnCore (c, false); } for (int r = 0; r < RowCount; r++) { if (rows [r].Selected) SetSelectedRowCore (r, false); } } for (int r = 0; r < RowCount; r++) { for (int c = 0; c < ColumnCount; c++) { bool select = (r >= min_row && r <= max_row) && (c >= min_col && c <= max_col); if (select != Rows [r].Cells [c].Selected) SetSelectedCellCore (c, r, select); } } break; } } else if (isControl) { // Switch the selected state of the row. switch (mode) { case DataGridViewSelectionMode.FullRowSelect: SetSelectedRowCore (hitTest.RowIndex, !rows [hitTest.RowIndex].Selected); break; case DataGridViewSelectionMode.FullColumnSelect: SetSelectedColumnCore (hitTest.ColumnIndex, !columns [hitTest.ColumnIndex].Selected); break; case DataGridViewSelectionMode.ColumnHeaderSelect: case DataGridViewSelectionMode.RowHeaderSelect: //break; case DataGridViewSelectionMode.CellSelect: if (hitTest.ColumnIndex >= 0 && hitTest.RowIndex >= 0) { SetSelectedCellCore (hitTest.ColumnIndex, hitTest.RowIndex, !Rows [hitTest.RowIndex].Cells [hitTest.ColumnIndex].Selected); } break; } } }
/// <summary> /// Returns an object with information on which portion of a toolbox control is at a location specified by a <see cref="Point"/>. /// </summary> /// <param name="location">A <see cref="Point"/> containing the <see cref="Point.X"/> and <see cref="Point.Y"/> coordinates of the point to be hit tested.</param> /// <returns>A <see cref="HitTestInfo"/> that contains information about the specified point on the <see cref="Toolbox"/>.</returns> public virtual HitTestInfo HitTest(Point location) { HitTestInfo info = new HitTestInfo(location); Rectangle tabsRect = this.ClientRectangle; tabsRect.Inflate(-Gap_TabBorder, -Gap_TabTop); if (tabsRect.Contains(location)) { foreach (Tab tab in this.Categories) { if ((this.ShowAll || tab.Visible) && tab.VisibleRectangle.Contains(location)) { return tab.HitTest(location); } } if (this.Items.Count > 0) { if (this.AllowToolboxItems) { foreach (Item item in this.Items) { if ((item.Visible || this.ShowAll) && item.Bounds.Contains(location)) { info.HitArea = HitArea.Item; info.Tool = item; break; } } } else { Tab toolboxItems = this.GetToolboxItemsTab(true); if ((toolboxItems.Visible || this.ShowAll) && toolboxItems.VisibleRectangle.Contains(location)) { info = toolboxItems.HitTest(location); } } } if (info.HitArea == HitArea.None) { info.HitArea = HitArea.Background; } } return info; }
protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); downHitInfo = new HitTestInfo(); }
private void OnCellSelectMouseMove(HitTestInfo hti) { Debug.Assert(this.MultiSelect); int oldEdgeColumnIndex = this.ptCurrentCell.X; int oldEdgeRowIndex = this.ptCurrentCell.Y; if ((hti.col != this.ptCurrentCell.X || hti.row != this.ptCurrentCell.Y) && !CommitEditForOperation(hti.col, hti.row, true)) { // Return silently if validating/commit/abort failed return; } this.noSelectionChangeCount++; try { if (this.ptAnchorCell.X == -1 || IsInnerCellOutOfBounds(hti.col, hti.row)) { return; } UpdateSelectedCellsBlock(this.ptAnchorCell.X, ref oldEdgeColumnIndex, hti.col, this.ptAnchorCell.Y, ref oldEdgeRowIndex, hti.row); if (hti.col != this.ptCurrentCell.X || hti.row != this.ptCurrentCell.Y) { bool success = SetCurrentCellAddressCore(hti.col, hti.row, false, false, false); Debug.Assert(success); } } finally { this.NoSelectionChangeCount--; } }
private void OnColumnHeaderMouseDown(HitTestInfo hti, bool isShiftDown, bool isControlDown) { Debug.Assert(hti.Type == DataGridViewHitTestType.ColumnHeader); this.noSelectionChangeCount++; try { switch (this.SelectionMode) { case DataGridViewSelectionMode.CellSelect: case DataGridViewSelectionMode.FullRowSelect: case DataGridViewSelectionMode.RowHeaderSelect: break; case DataGridViewSelectionMode.FullColumnSelect: case DataGridViewSelectionMode.ColumnHeaderSelect: { bool select = true; if (isControlDown && this.Columns[hti.col].Selected) { select = false; } if (select) { int rowIndex = this.Rows.GetFirstRow(DataGridViewElementStates.Visible); if (rowIndex > -1 && hti.col != this.ptCurrentCell.X) { // Make sure we will be able to scroll into view int oldCurrentCellX = this.ptCurrentCell.X; int oldCurrentCellY = this.ptCurrentCell.Y; if (!EndEdit(DataGridViewDataErrorContexts.Parsing | DataGridViewDataErrorContexts.Commit | DataGridViewDataErrorContexts.CurrentCellChange, DataGridViewValidateCellInternal.Always /*validateCell*/, true /*fireCellLeave*/, true /*fireCellEnter*/, rowIndex != this.ptCurrentCell.Y /*fireRowLeave*/, rowIndex != this.ptCurrentCell.Y /*fireRowEnter*/, false /*fireLeave*/, this.EditMode != DataGridViewEditMode.EditOnEnter /*keepFocus*/, true /*resetCurrentCell*/, false /*resetAnchorCell*/)) { // Just cancel operation silently instead of throwing InvalidOperationException return; } if (rowIndex != oldCurrentCellY && oldCurrentCellY != -1) { DataGridViewCell dataGridViewCellTmp = null; if (IsInnerCellOutOfBounds(oldCurrentCellX, oldCurrentCellY)) { return; } if (OnRowValidating(ref dataGridViewCellTmp, oldCurrentCellX, oldCurrentCellY)) { // Row validation was cancelled if (IsInnerCellOutOfBounds(oldCurrentCellX, oldCurrentCellY)) { return; } OnRowEnter(ref dataGridViewCellTmp, oldCurrentCellX, oldCurrentCellY, true /*canCreateNewRow*/, true /*validationFailureOccurred*/); if (IsInnerCellOutOfBounds(oldCurrentCellX, oldCurrentCellY)) { return; } OnCellEnter(ref dataGridViewCellTmp, oldCurrentCellX, oldCurrentCellY); return; } if (IsInnerCellOutOfBounds(oldCurrentCellX, oldCurrentCellY)) { return; } OnRowValidated(ref dataGridViewCellTmp, oldCurrentCellX, oldCurrentCellY); } } if (IsColumnOutOfBounds(hti.col)) { return; } bool selectColumnRange = false; this.trackColumn = hti.col; this.trackColumnEdge = -1; if (this.MultiSelect && isShiftDown && this.ptAnchorCell.X > -1 && this.Columns[this.ptAnchorCell.X].Selected) { selectColumnRange = true; } if (!this.MultiSelect || !isControlDown || isShiftDown) { Debug.Assert(this.MultiSelect || this.selectedBandIndexes.Count <= 1); int bandIndex = 0; bool switchedToBulkPaint = false; if (this.selectedBandIndexes.Count > DATAGRIDVIEW_bulkPaintThreshold) { this.inBulkPaintCount++; switchedToBulkPaint = true; } try { while (bandIndex < this.selectedBandIndexes.Count) { if (this.selectedBandIndexes[bandIndex] != hti.col) { // deselect currently selected column SetSelectedColumnCore(this.selectedBandIndexes[bandIndex], false); } else { bandIndex++; } } if (this.SelectionMode == DataGridViewSelectionMode.ColumnHeaderSelect) { RemoveIndividuallySelectedCells(); } else { Debug.Assert(this.individualSelectedCells.Count == 0); } } finally { if (switchedToBulkPaint) { ExitBulkPaint(-1, -1); } } } if (this.MultiSelect && this.dataGridViewOper[DATAGRIDVIEWOPER_trackMouseMoves]) { this.dataGridViewOper[DATAGRIDVIEWOPER_trackColSelect] = true; } if (selectColumnRange) { if (this.Columns.DisplayInOrder(this.ptAnchorCell.X, hti.col)) { SelectColumnRange(this.ptAnchorCell.X, hti.col, true); } else { SelectColumnRange(hti.col, this.ptAnchorCell.X, true); } } else if (!this.selectedBandIndexes.Contains(hti.col)) { SetSelectedColumnCore(hti.col, true); } // set current cell to the top most visible cell in the column if (rowIndex != -1) { if (hti.col != this.ptCurrentCell.X) { if (IsInnerCellOutOfBounds(hti.col, rowIndex)) { return; } bool success = ScrollIntoView(hti.col, rowIndex, false); Debug.Assert(success); if (IsInnerCellOutOfBounds(hti.col, rowIndex)) { return; } success = SetCurrentCellAddressCore(hti.col, rowIndex, !isShiftDown, false, true); Debug.Assert(success); } else if (-1 != this.ptCurrentCell.X) { // Potentially have to give focus back to the current edited cell. bool success = SetCurrentCellAddressCore(this.ptCurrentCell.X, this.ptCurrentCell.Y, false /*setAnchorCellAddress*/, false /*validateCurrentCell*/, false /*throughMouseClick*/); Debug.Assert(success); } } else { Debug.Assert(this.CurrentCellAddress == new Point(-1, -1)); } } else { Debug.Assert(this.selectedBandIndexes.Contains(hti.col)); SetSelectedColumnCore(hti.col, false); } break; } } } finally { this.NoSelectionChangeCount--; } }
private void MoveColumnRelocation(MouseEventArgs e, HitTestInfo hti) { this.lastHeaderShadow = e.X; this.dataGridViewState2[DATAGRIDVIEWSTATE2_showColumnRelocationInsertion] = ColumnRelocationTarget(e, hti, out this.trackColumnEdge); Invalidate(Rectangle.Union(this.layout.TopLeftHeader, this.layout.ColumnHeaders)); }
private void OnCellMouseDown(HitTestInfo hti, bool isShiftDown, bool isControlDown) { Debug.Assert(hti.Type == DataGridViewHitTestType.Cell); // Only commit cell if the target cell is different from the current one. if (this.ptCurrentCell.X >= 0 && (this.ptCurrentCell.X != hti.col || this.ptCurrentCell.Y != hti.row)) { Point ptOriginalCurrentCell = this.ptCurrentCell; if (!CommitEdit(DataGridViewDataErrorContexts.Parsing | DataGridViewDataErrorContexts.Commit, this.ptCurrentCell.X != hti.col || this.ptCurrentCell.Y != hti.row /*forCurrentCellChange*/, this.ptCurrentCell.Y != hti.row /*forCurrentRowChange*/)) { // Return silently if validating/commit/abort failed return; } if (this.ptCurrentCell != ptOriginalCurrentCell) { // VSWhidbey 492203. Somehow the fact that the current cell was committed altered the current cell value. // To avoid unintentional multi-selections, we act as if Shift and Control keys were up. isShiftDown = isControlDown = false; } } if (hti.col >= this.Columns.Count) { DataGridViewColumn dataGridViewLastVisibleColumn = this.Columns.GetLastColumn(DataGridViewElementStates.Visible, DataGridViewElementStates.None); if (this.ptCurrentCell.X == -1 && dataGridViewLastVisibleColumn != null) { // CurrentCell was reset because CommitEdit deleted column(s). // Since the user clicked on a cell, we don't want to end up // with no CurrentCell. We pick the last visible column in the grid. hti.col = dataGridViewLastVisibleColumn.Index; } else { return; } } if (hti.row >= this.Rows.Count) { int lastVisibleRowIndex = this.Rows.GetLastRow(DataGridViewElementStates.Visible); if (this.ptCurrentCell.X == -1 && lastVisibleRowIndex != -1) { // CurrentCell was reset because CommitEdit deleted row(s). // Since the user clicked on a cell, we don't want to end up // with no CurrentCell. We pick the last visible row in the // grid which may be the 'new row'. hti.row = lastVisibleRowIndex; } else { return; } } bool select = true; this.noSelectionChangeCount++; try { switch (this.SelectionMode) { case DataGridViewSelectionMode.CellSelect: { if (isControlDown && IsSharedCellSelected(this.Rows.SharedRow(hti.row).Cells[hti.col], hti.row) && (!isShiftDown || !this.MultiSelect)) { select = false; } if (select) { if ((!this.MultiSelect || !isControlDown) && !(this.MultiSelect && isShiftDown)) { Debug.Assert(this.MultiSelect || this.individualSelectedCells.Count <= 1); RemoveIndividuallySelectedCells(hti.col, hti.row); } if (this.MultiSelect) { if (this.dataGridViewOper[DATAGRIDVIEWOPER_trackMouseMoves]) { this.dataGridViewOper[DATAGRIDVIEWOPER_trackCellSelect] = true; } if (isShiftDown) { int oldEdgeColumnIndex = this.ptCurrentCell.X; int oldEdgeRowIndex = this.ptCurrentCell.Y; if (this.ptAnchorCell.X == -1) { return; } UpdateSelectedCellsBlock(this.ptAnchorCell.X, ref oldEdgeColumnIndex, hti.col, this.ptAnchorCell.Y, ref oldEdgeRowIndex, hti.row); } else { SetSelectedCellCore(hti.col, hti.row, true); } } else { SetSelectedCellCore(hti.col, hti.row, true); } } else { SetSelectedCellCore(hti.col, hti.row, false); } bool success = SetCurrentCellAddressCore(hti.col, hti.row, !isShiftDown, false, true); Debug.Assert(success); break; } case DataGridViewSelectionMode.FullColumnSelect: { if (isControlDown && this.Columns[hti.col].Selected) { select = false; } if (select) { bool selectColumnRange = false; this.trackColumn = hti.col; this.trackColumnEdge = -1; if (this.MultiSelect && isShiftDown && this.ptAnchorCell.X > -1 && this.Columns[this.ptAnchorCell.X].Selected) { selectColumnRange = true; } if (!this.MultiSelect || !isControlDown || isShiftDown) { Debug.Assert(this.MultiSelect || this.selectedBandIndexes.Count <= 1); int bandIndex = 0; bool switchedToBulkPaint = false; if (this.selectedBandIndexes.Count > DATAGRIDVIEW_bulkPaintThreshold) { this.inBulkPaintCount++; switchedToBulkPaint = true; } try { while (bandIndex < this.selectedBandIndexes.Count) { if (this.selectedBandIndexes[bandIndex] != hti.col) { // deselect currently selected column SetSelectedColumnCore(this.selectedBandIndexes[bandIndex], false); } else { bandIndex++; } } } finally { if (switchedToBulkPaint) { ExitBulkPaint(-1, -1); } } } if (this.MultiSelect && this.dataGridViewOper[DATAGRIDVIEWOPER_trackMouseMoves]) { this.dataGridViewOper[DATAGRIDVIEWOPER_trackColSelect] = true; } if (selectColumnRange) { if (this.Columns.DisplayInOrder(this.ptAnchorCell.X, hti.col)) { SelectColumnRange(this.ptAnchorCell.X, hti.col, true); } else { SelectColumnRange(hti.col, this.ptAnchorCell.X, true); } } else if (!this.selectedBandIndexes.Contains(hti.col)) { SetSelectedColumnCore(hti.col, true); } } else { Debug.Assert(this.selectedBandIndexes.Contains(hti.col)); SetSelectedColumnCore(hti.col, false); } bool success = SetCurrentCellAddressCore(hti.col, hti.row, !isShiftDown, false, true); Debug.Assert(success); break; } case DataGridViewSelectionMode.ColumnHeaderSelect: { if (isControlDown && (this.Columns[hti.col].Selected || IsSharedCellSelected(this.Rows.SharedRow(hti.row).Cells[hti.col], hti.row)) && (!isShiftDown || !this.MultiSelect)) { select = false; } if (select) { if (!this.MultiSelect) { Debug.Assert(this.selectedBandIndexes.Count <= 1); if (this.selectedBandIndexes.Count > 0) { SetSelectedColumnCore(this.selectedBandIndexes.HeadInt, false); } else { RemoveIndividuallySelectedCells(); } SetSelectedCellCore(hti.col, hti.row, true); } else { // this.MultiSelect == true if (!isControlDown && !isShiftDown) { bool switchedToBulkPaint = false; if (this.selectedBandIndexes.Count > DATAGRIDVIEW_bulkPaintThreshold) { this.inBulkPaintCount++; switchedToBulkPaint = true; } try { while (this.selectedBandIndexes.Count > 0) { SetSelectedColumnCore(this.selectedBandIndexes.HeadInt, false); } RemoveIndividuallySelectedCells(hti.col, hti.row); } finally { if (switchedToBulkPaint) { ExitBulkPaint(-1, -1); } } } if (this.dataGridViewOper[DATAGRIDVIEWOPER_trackMouseMoves]) { this.dataGridViewOper[DATAGRIDVIEWOPER_trackCellSelect] = true; } if (isShiftDown) { int oldEdgeColumnIndex = this.ptCurrentCell.X; int oldEdgeRowIndex = this.ptCurrentCell.Y; if (this.ptAnchorCell.X == -1) { return; } UpdateSelectedCellsBlock(this.ptAnchorCell.X, ref oldEdgeColumnIndex, hti.col, this.ptAnchorCell.Y, ref oldEdgeRowIndex, hti.row); } else { SetSelectedCellCore(hti.col, hti.row, true); } } } else { if (!this.MultiSelect) { Debug.Assert(this.selectedBandIndexes.Count <= 1); if (this.selectedBandIndexes.Count > 0) { SetSelectedColumnCore(this.selectedBandIndexes.HeadInt, false); } else { SetSelectedCellCore(hti.col, hti.row, false); } } else { SetSelectedCellCore(hti.col, hti.row, false); } } bool success = SetCurrentCellAddressCore(hti.col, hti.row, !isShiftDown, false, true); Debug.Assert(success); break; } case DataGridViewSelectionMode.FullRowSelect: { if (isControlDown && ((this.Rows.GetRowState(hti.row) & DataGridViewElementStates.Selected) != 0)) { select = false; } if (select) { bool selectRowRange = false; this.trackRow = hti.row; this.trackRowEdge = -1; if (this.MultiSelect && isShiftDown && this.ptAnchorCell.Y > -1 && (this.Rows.GetRowState(this.ptAnchorCell.Y) & DataGridViewElementStates.Selected) != 0) { selectRowRange = true; } if (!this.MultiSelect || !isControlDown || isShiftDown) { Debug.Assert(this.MultiSelect || this.selectedBandIndexes.Count <= 1); int bandIndex = 0; bool switchedToBulkPaint = false; if (this.selectedBandIndexes.Count > DATAGRIDVIEW_bulkPaintThreshold) { this.inBulkPaintCount++; switchedToBulkPaint = true; } try { while (bandIndex < this.selectedBandIndexes.Count) { if (this.selectedBandIndexes[bandIndex] != hti.row) { // deselect currently selected row SetSelectedRowCore(this.selectedBandIndexes[bandIndex], false); } else { bandIndex++; } } } finally { if (switchedToBulkPaint) { ExitBulkPaint(-1, -1); } } } if (this.MultiSelect && this.dataGridViewOper[DATAGRIDVIEWOPER_trackMouseMoves]) { this.dataGridViewOper[DATAGRIDVIEWOPER_trackRowSelect] = true; } if (selectRowRange) { if (hti.row >= this.ptAnchorCell.Y) { SelectRowRange(this.ptAnchorCell.Y, hti.row, true); } else { SelectRowRange(hti.row, this.ptAnchorCell.Y, true); } } else if ((this.Rows.GetRowState(hti.row) & DataGridViewElementStates.Selected) == 0) { Debug.Assert(this.selectedBandIndexes.Contains(hti.row) == ((this.Rows.GetRowState(hti.row) & DataGridViewElementStates.Selected) != 0)); SetSelectedRowCore(hti.row, true); } } else { Debug.Assert(this.selectedBandIndexes.Contains(hti.row)); SetSelectedRowCore(hti.row, false); } bool success = SetCurrentCellAddressCore(hti.col, hti.row, !isShiftDown, false, true); Debug.Assert(success); break; } case DataGridViewSelectionMode.RowHeaderSelect: { if (isControlDown && (((this.Rows.GetRowState(hti.row) & DataGridViewElementStates.Selected) != 0) || IsSharedCellSelected(this.Rows.SharedRow(hti.row).Cells[hti.col], hti.row)) && (!isShiftDown || !this.MultiSelect)) { select = false; } if (select) { if (!this.MultiSelect) { Debug.Assert(this.selectedBandIndexes.Count <= 1); if (this.selectedBandIndexes.Count > 0) { SetSelectedRowCore(this.selectedBandIndexes.HeadInt, false); } else { RemoveIndividuallySelectedCells(); } SetSelectedCellCore(hti.col, hti.row, true); } else { // this.MultiSelect == true if (!isControlDown && !isShiftDown) { bool switchedToBulkPaint = false; if (this.selectedBandIndexes.Count > DATAGRIDVIEW_bulkPaintThreshold) { this.inBulkPaintCount++; switchedToBulkPaint = true; } try { while (this.selectedBandIndexes.Count > 0) { SetSelectedRowCore(this.selectedBandIndexes.HeadInt, false); } RemoveIndividuallySelectedCells(hti.col, hti.row); } finally { if (switchedToBulkPaint) { ExitBulkPaint(-1, -1); } } } if (this.dataGridViewOper[DATAGRIDVIEWOPER_trackMouseMoves]) { this.dataGridViewOper[DATAGRIDVIEWOPER_trackCellSelect] = true; } if (isShiftDown) { int oldEdgeColumnIndex = this.ptCurrentCell.X; int oldEdgeRowIndex = this.ptCurrentCell.Y; if (this.ptAnchorCell.X == -1) { return; } UpdateSelectedCellsBlock(this.ptAnchorCell.X, ref oldEdgeColumnIndex, hti.col, this.ptAnchorCell.Y, ref oldEdgeRowIndex, hti.row); } else { SetSelectedCellCore(hti.col, hti.row, true); } } } else { if (!this.MultiSelect) { Debug.Assert(this.selectedBandIndexes.Count <= 1); if (this.selectedBandIndexes.Count > 0) { SetSelectedRowCore(this.selectedBandIndexes.HeadInt, false); } else { SetSelectedCellCore(hti.col, hti.row, false); } } else { SetSelectedCellCore(hti.col, hti.row, false); } } bool success = SetCurrentCellAddressCore(hti.col, hti.row, !isShiftDown, false, true); // [....]: SetCurrentCellAddressCore can fail if by navigating to a cell the list under the // DataGridView changes. // See vsWhidbey: 325296. // Debug.Assert(success); break; } } } finally { this.NoSelectionChangeCount--; } }
private bool GetOutOfBoundCorrectedHitTestInfo(ref HitTestInfo hti, ref int mouseX, ref int mouseY, out int xOffset, out int yOffset) { xOffset = yOffset = 0; Rectangle data = this.layout.Data; int rowsHeight = this.Rows.GetRowsHeight(DataGridViewElementStates.Visible); int totalVisibleFrozenHeight = this.Rows.GetRowsHeight(DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen); int num3 = this.ComputeHeightOfFittingTrailingScrollingRows(totalVisibleFrozenHeight); int num4 = this.ComputeHeightOfTrailingScrollingRows(); int emptyBackgroundWidth = Math.Max(0, this.layout.Data.Width - this.Columns.GetColumnsWidth(DataGridViewElementStates.Visible)); int emptyBackgroundHeight = Math.Max(0, (this.layout.Data.Height - totalVisibleFrozenHeight) - num4); if (this.dataGridViewOper[8]) { if (this.layout.RowHeadersVisible) { data = Rectangle.Union(data, this.layout.RowHeaders); } this.DiscardZonesInScrollingArea(ref data, emptyBackgroundWidth, emptyBackgroundHeight, totalVisibleFrozenHeight, false, true); if ((mouseY >= data.Top) && (mouseY <= data.Bottom)) { hti = this.HitTest(this.RightToLeftInternal ? (data.Right - 1) : data.Left, mouseY); if ((((this.ptAnchorCell.Y != -1) && ((this.Rows.GetRowState(this.ptAnchorCell.Y) & DataGridViewElementStates.Frozen) != DataGridViewElementStates.None)) && ((this.trackRowEdge != -1) && ((this.Rows.GetRowState(this.trackRowEdge) & DataGridViewElementStates.Frozen) != DataGridViewElementStates.None))) && ((hti.row >= 0) && ((this.Rows.GetRowState(hti.row) & DataGridViewElementStates.Frozen) == DataGridViewElementStates.None))) { int col; int firstRow = this.Rows.GetFirstRow(DataGridViewElementStates.Visible, DataGridViewElementStates.Frozen); if (hti.col >= 0) { col = hti.col; } else { DataGridViewColumn firstColumn = this.Columns.GetFirstColumn(DataGridViewElementStates.Visible); col = (firstColumn == null) ? -1 : firstColumn.Index; } if ((col >= 0) && (firstRow >= 0)) { if (!this.ScrollIntoView(col, firstRow, false)) { return false; } hti = this.HitTest(this.RightToLeftInternal ? data.Right : data.Left, mouseY); } } return true; } if (mouseY < data.Top) { if (((this.ptAnchorCell.Y != -1) && (((this.Rows.GetRowState(this.ptAnchorCell.Y) & DataGridViewElementStates.Frozen) == DataGridViewElementStates.None) || ((this.trackRowEdge != -1) && ((this.Rows.GetRowState(this.trackRowEdge) & DataGridViewElementStates.Frozen) == DataGridViewElementStates.None)))) && (this.verticalOffset != 0)) { yOffset = mouseY - data.Top; if (this.RightToLeftInternal) { mouseX = data.Right - 1; } else { mouseX = data.Left + 1; } } else { hti = this.HitTest(this.RightToLeftInternal ? data.Right : data.Left, mouseY); } } else if ((this.displayedBandsInfo.FirstDisplayedScrollingRow >= 0) && ((this.verticalOffset + this.Rows.SharedRow(this.displayedBandsInfo.FirstDisplayedScrollingRow).GetHeight(this.displayedBandsInfo.FirstDisplayedScrollingRow)) <= ((rowsHeight - totalVisibleFrozenHeight) - num3))) { yOffset = mouseY - data.Bottom; if (this.RightToLeftInternal) { mouseX = data.Right - 1; } else { mouseX = data.Left + 1; } } return true; } if (this.dataGridViewOper[4]) { if (this.layout.ColumnHeadersVisible) { data = Rectangle.Union(data, this.layout.ColumnHeaders); } this.DiscardZonesInScrollingArea(ref data, emptyBackgroundWidth, emptyBackgroundHeight, totalVisibleFrozenHeight, true, false); if ((mouseX >= data.Left) && (mouseX <= data.Right)) { hti = this.HitTest(mouseX, data.Top); if ((((this.ptAnchorCell.X != -1) && this.Columns[this.ptAnchorCell.X].Frozen) && ((this.trackColumnEdge != -1) && this.Columns[this.trackColumnEdge].Frozen)) && ((hti.col >= 0) && !this.Columns[hti.col].Frozen)) { int row; int index = this.Columns.GetFirstColumn(DataGridViewElementStates.Visible, DataGridViewElementStates.Frozen).Index; if (hti.row >= 0) { row = hti.row; } else { row = this.Rows.GetFirstRow(DataGridViewElementStates.Visible); } if ((row >= 0) && (index >= 0)) { if (!this.ScrollIntoView(index, row, false)) { return false; } hti = this.HitTest(mouseX, data.Top); } } return true; } if ((!this.RightToLeftInternal && (mouseX < data.Left)) || (this.RightToLeftInternal && (mouseX > data.Right))) { if (((this.ptAnchorCell.X != -1) && (!this.Columns[this.ptAnchorCell.X].Frozen || ((this.trackColumnEdge != -1) && !this.Columns[this.trackColumnEdge].Frozen))) && ((this.displayedBandsInfo.FirstDisplayedScrollingCol >= 0) && ((this.negOffset > 0) || (this.Columns.GetPreviousColumn(this.Columns[this.displayedBandsInfo.FirstDisplayedScrollingCol], DataGridViewElementStates.Visible, DataGridViewElementStates.Frozen) != null)))) { if (this.RightToLeftInternal) { xOffset = data.Right - mouseX; } else { xOffset = mouseX - data.Left; } mouseY = data.Top + 1; } else { hti = this.HitTest(mouseX, data.Top); } } else if (this.displayedBandsInfo.FirstDisplayedScrollingCol >= 0) { if ((this.displayedBandsInfo.LastTotallyDisplayedScrollingCol != -1) && (this.Columns.GetNextColumn(this.Columns[this.displayedBandsInfo.LastTotallyDisplayedScrollingCol], DataGridViewElementStates.Visible, DataGridViewElementStates.None) == null)) { return true; } DataGridViewColumn column2 = this.Columns.GetNextColumn(this.Columns[this.displayedBandsInfo.FirstDisplayedScrollingCol], DataGridViewElementStates.Visible, DataGridViewElementStates.None); int num11 = 0; for (DataGridViewColumn column3 = this.Columns.GetFirstColumn(DataGridViewElementStates.Visible, DataGridViewElementStates.Frozen); column3 != column2; column3 = this.Columns.GetNextColumn(column3, DataGridViewElementStates.Visible, DataGridViewElementStates.None)) { num11 += column3.Thickness; } if (this.HorizontalOffset != num11) { if (this.RightToLeftInternal) { xOffset = data.Left - mouseX; } else { xOffset = mouseX - data.Right; } mouseY = data.Top + 1; } } return true; } if (this.dataGridViewOper[0x10]) { bool flag = false; this.DiscardZonesInScrollingArea(ref data, emptyBackgroundWidth, emptyBackgroundHeight, totalVisibleFrozenHeight, true, true); if (mouseY < data.Top) { if ((((this.ptAnchorCell.Y != -1) && ((this.Rows.GetRowState(this.ptAnchorCell.Y) & DataGridViewElementStates.Frozen) == DataGridViewElementStates.None)) || ((this.ptCurrentCell.Y != -1) && ((this.Rows.GetRowState(this.ptCurrentCell.Y) & DataGridViewElementStates.Frozen) == DataGridViewElementStates.None))) && (this.verticalOffset != 0)) { yOffset = mouseY - data.Top; } else if (mouseY < this.layout.Data.Top) { mouseY = this.layout.Data.Top + 1; flag = true; } } else if (mouseY > data.Bottom) { if (this.displayedBandsInfo.FirstDisplayedScrollingRow >= 0) { if ((this.verticalOffset + this.Rows.SharedRow(this.displayedBandsInfo.FirstDisplayedScrollingRow).GetHeight(this.displayedBandsInfo.FirstDisplayedScrollingRow)) <= ((rowsHeight - totalVisibleFrozenHeight) - num3)) { yOffset = mouseY - data.Bottom; } else { mouseY = data.Bottom - 1; flag = true; } } else { mouseY = data.Bottom - 1; flag = true; } } if ((!this.RightToLeftInternal && (mouseX < data.Left)) || (this.RightToLeftInternal && (mouseX > data.Right))) { if ((((this.ptAnchorCell.X != -1) && !this.Columns[this.ptAnchorCell.X].Frozen) || ((this.ptCurrentCell.X != -1) && !this.Columns[this.ptCurrentCell.X].Frozen)) && ((this.displayedBandsInfo.FirstDisplayedScrollingCol >= 0) && ((this.negOffset > 0) || (this.Columns.GetPreviousColumn(this.Columns[this.displayedBandsInfo.FirstDisplayedScrollingCol], DataGridViewElementStates.Visible, DataGridViewElementStates.Frozen) != null)))) { if (this.RightToLeftInternal) { xOffset = data.Right - mouseX; } else { xOffset = mouseX - data.Left; } } else if (!this.RightToLeftInternal && (mouseX < this.layout.Data.Left)) { mouseX = this.layout.Data.Left + 1; flag = true; } else if (this.RightToLeftInternal && (mouseX > this.layout.Data.Right)) { mouseX = this.layout.Data.Right - 1; flag = true; } } else if ((!this.RightToLeftInternal && (mouseX > data.Right)) || (this.RightToLeftInternal && (mouseX < data.Left))) { if ((this.displayedBandsInfo.FirstDisplayedScrollingCol >= 0) && ((this.displayedBandsInfo.LastTotallyDisplayedScrollingCol == -1) || (this.Columns.GetNextColumn(this.Columns[this.displayedBandsInfo.LastTotallyDisplayedScrollingCol], DataGridViewElementStates.Visible, DataGridViewElementStates.None) != null))) { DataGridViewColumn column4 = this.Columns.GetNextColumn(this.Columns[this.displayedBandsInfo.FirstDisplayedScrollingCol], DataGridViewElementStates.Visible, DataGridViewElementStates.None); int num12 = 0; for (DataGridViewColumn column5 = this.Columns.GetFirstColumn(DataGridViewElementStates.Visible, DataGridViewElementStates.Frozen); column5 != column4; column5 = this.Columns.GetNextColumn(column5, DataGridViewElementStates.Visible, DataGridViewElementStates.None)) { num12 += column5.Thickness; } if (this.HorizontalOffset != num12) { if (this.RightToLeftInternal) { xOffset = data.Left - mouseX; } else { xOffset = mouseX - data.Right; } } else { if (this.RightToLeftInternal) { mouseX = data.Left + 1; } else { mouseX = data.Right - 1; } flag = true; } } else { if (this.RightToLeftInternal) { mouseX = data.Left + 1; } else { mouseX = data.Right - 1; } flag = true; } } if (flag) { hti = this.HitTest(mouseX, mouseY); } } return true; }
// set one item clicked and all others off private void SetItemClick(HitTestInfo hti) { switch(hti.HitArea) { case HitArea.NextMonthButton: this.is_previous_clicked = false; this.is_next_clicked = true; this.is_date_clicked = false; break; case HitArea.PrevMonthButton: this.is_previous_clicked = true; this.is_next_clicked = false; this.is_date_clicked = false; break; case HitArea.PrevMonthDate: case HitArea.NextMonthDate: case HitArea.Date: this.clicked_date = hti.hit_time; this.is_previous_clicked = false; this.is_next_clicked = false; this.is_date_clicked = true; break; default : this.is_previous_clicked = false; this.is_next_clicked = false; this.is_date_clicked = false; break; } }
private void OnColumnHeaderMouseDown(HitTestInfo hti, bool isShiftDown, bool isControlDown) { this.noSelectionChangeCount++; try { int firstRow; int x; int y; DataGridViewCell cell; switch (this.SelectionMode) { case DataGridViewSelectionMode.CellSelect: case DataGridViewSelectionMode.FullRowSelect: case DataGridViewSelectionMode.RowHeaderSelect: return; case DataGridViewSelectionMode.FullColumnSelect: case DataGridViewSelectionMode.ColumnHeaderSelect: { bool flag = true; if (isControlDown && this.Columns[hti.col].Selected) { flag = false; } if (!flag) { goto Label_0385; } firstRow = this.Rows.GetFirstRow(DataGridViewElementStates.Visible); if ((firstRow <= -1) || (hti.col == this.ptCurrentCell.X)) { goto Label_015C; } x = this.ptCurrentCell.X; y = this.ptCurrentCell.Y; if (this.EndEdit(DataGridViewDataErrorContexts.CurrentCellChange | DataGridViewDataErrorContexts.Commit | DataGridViewDataErrorContexts.Parsing, DataGridViewValidateCellInternal.Always, true, true, firstRow != this.ptCurrentCell.Y, firstRow != this.ptCurrentCell.Y, false, this.EditMode != DataGridViewEditMode.EditOnEnter, true, false)) { if ((firstRow == y) || (y == -1)) { goto Label_015C; } cell = null; if (!this.IsInnerCellOutOfBounds(x, y)) { if (!this.OnRowValidating(ref cell, x, y)) { break; } if (!this.IsInnerCellOutOfBounds(x, y)) { this.OnRowEnter(ref cell, x, y, true, true); if (!this.IsInnerCellOutOfBounds(x, y)) { this.OnCellEnter(ref cell, x, y); } } } } return; } default: return; } if (this.IsInnerCellOutOfBounds(x, y)) { return; } this.OnRowValidated(ref cell, x, y); Label_015C: if (!this.IsColumnOutOfBounds(hti.col)) { bool flag2 = false; this.trackColumn = hti.col; this.trackColumnEdge = -1; if ((this.MultiSelect && isShiftDown) && ((this.ptAnchorCell.X > -1) && this.Columns[this.ptAnchorCell.X].Selected)) { flag2 = true; } if ((!this.MultiSelect || !isControlDown) || isShiftDown) { int num4 = 0; bool flag3 = false; if (this.selectedBandIndexes.Count > 8) { this.inBulkPaintCount++; flag3 = true; } try { while (num4 < this.selectedBandIndexes.Count) { if (this.selectedBandIndexes[num4] != hti.col) { this.SetSelectedColumnCore(this.selectedBandIndexes[num4], false); } else { num4++; } } if (this.SelectionMode == DataGridViewSelectionMode.ColumnHeaderSelect) { this.RemoveIndividuallySelectedCells(); } } finally { if (flag3) { this.ExitBulkPaint(-1, -1); } } } if (this.MultiSelect && this.dataGridViewOper[0x200]) { this.dataGridViewOper[4] = true; } if (flag2) { if (this.Columns.DisplayInOrder(this.ptAnchorCell.X, hti.col)) { this.SelectColumnRange(this.ptAnchorCell.X, hti.col, true); } else { this.SelectColumnRange(hti.col, this.ptAnchorCell.X, true); } } else if (!this.selectedBandIndexes.Contains(hti.col)) { this.SetSelectedColumnCore(hti.col, true); } if (firstRow != -1) { if (hti.col != this.ptCurrentCell.X) { if (!this.IsInnerCellOutOfBounds(hti.col, firstRow)) { this.ScrollIntoView(hti.col, firstRow, false); if (!this.IsInnerCellOutOfBounds(hti.col, firstRow)) { this.SetCurrentCellAddressCore(hti.col, firstRow, !isShiftDown, false, true); } } } else if (-1 != this.ptCurrentCell.X) { this.SetCurrentCellAddressCore(this.ptCurrentCell.X, this.ptCurrentCell.Y, false, false, false); } } } return; Label_0385: this.SetSelectedColumnCore(hti.col, false); } finally { this.NoSelectionChangeCount--; } }
/// <include file='doc\DataGridView.uex' path='docs/doc[@for="DataGridView.HitTest"]/*' /> public HitTestInfo HitTest(int x, int y) { HitTestInfo hti = new HitTestInfo(); if (!this.layout.Inside.Contains(x, y)) { return hti; } if (this.horizScrollBar != null && this.horizScrollBar.Visible && this.horizScrollBar.Bounds.Contains(x, y)) { hti.type = DataGridViewHitTestType.HorizontalScrollBar; return hti; } if (this.vertScrollBar != null && this.vertScrollBar.Visible && this.vertScrollBar.Bounds.Contains(x, y)) { hti.type = DataGridViewHitTestType.VerticalScrollBar; return hti; } if (this.layout.TopLeftHeader.Contains(x, y)) { hti.type = DataGridViewHitTestType.TopLeftHeader; hti.typeInternal = DataGridViewHitTestTypeInternal.TopLeftHeader; if (this.RightToLeftInternal) { hti.colStart = this.layout.TopLeftHeader.Right-1; } else { hti.colStart = this.layout.TopLeftHeader.Left; } hti.rowStart = this.layout.TopLeftHeader.Top; if ((!this.RightToLeftInternal && this.layout.TopLeftHeader.Right - x < DATAGRIDVIEW_columnSizingHotZone) || (this.RightToLeftInternal && x - this.layout.TopLeftHeader.Left < DATAGRIDVIEW_columnSizingHotZone)) { //hti.edge = DataGridViewHitTestTypeCloseEdge.Right; if (this.RowHeadersWidthSizeMode == DataGridViewRowHeadersWidthSizeMode.EnableResizing) { hti.typeInternal = DataGridViewHitTestTypeInternal.TopLeftHeaderResizeLeft; if (this.RightToLeftInternal) { hti.mouseBarOffset = this.layout.TopLeftHeader.Left - x - 1; } else { hti.mouseBarOffset = this.layout.TopLeftHeader.Right - x - 1; } } } else if (this.layout.TopLeftHeader.Top + this.layout.TopLeftHeader.Height - y < DATAGRIDVIEW_rowSizingHotZone) { //hti.edge = DataGridViewHitTestTypeCloseEdge.Bottom; if (this.ColumnHeadersHeightSizeMode == DataGridViewColumnHeadersHeightSizeMode.EnableResizing) { hti.typeInternal = DataGridViewHitTestTypeInternal.TopLeftHeaderResizeTop; hti.mouseBarOffset = this.layout.TopLeftHeader.Top + this.layout.TopLeftHeader.Height - y - 1; } } return hti; } // check for column resize / insertion if (this.layout.ColumnHeaders.Contains(x, y)) { int xColumnLeftEdge; // this is actually the right edge in RTL mode hti.col = GetColumnIndexFromX(x, out xColumnLeftEdge); if (hti.col < 0) { return HitTestInfo.Nowhere; } Debug.Assert(xColumnLeftEdge == GetColumnXFromIndex(hti.col)); hti.type = DataGridViewHitTestType.ColumnHeader; hti.typeInternal = DataGridViewHitTestTypeInternal.ColumnHeader; hti.rowStart = this.layout.ColumnHeaders.Top; hti.colStart = xColumnLeftEdge; int columnWidth = this.Columns[hti.col].Thickness; if ((!this.RightToLeftInternal && xColumnLeftEdge + columnWidth - x < DATAGRIDVIEW_columnSizingHotZone) || (this.RightToLeftInternal && x - xColumnLeftEdge + columnWidth < DATAGRIDVIEW_columnSizingHotZone)) { //hti.edge = DataGridViewHitTestTypeCloseEdge.Right; if (this.RightToLeftInternal) { hti.mouseBarOffset = xColumnLeftEdge - columnWidth - x + 1; } else { hti.mouseBarOffset = xColumnLeftEdge + columnWidth - x - 1; } DataGridViewColumn dataGridViewColumn = this.Columns[hti.col]; if (dataGridViewColumn.Resizable == DataGridViewTriState.True && (dataGridViewColumn.InheritedAutoSizeMode == DataGridViewAutoSizeColumnMode.None || dataGridViewColumn.InheritedAutoSizeMode == DataGridViewAutoSizeColumnMode.Fill)) { hti.typeInternal = DataGridViewHitTestTypeInternal.ColumnResizeRight; } else { hti.typeInternal = DataGridViewHitTestTypeInternal.ColumnHeaderRight; } } else if ((!this.RightToLeftInternal && x - xColumnLeftEdge < DATAGRIDVIEW_columnSizingHotZone) || (this.RightToLeftInternal && xColumnLeftEdge - x < DATAGRIDVIEW_columnSizingHotZone)) { //hti.edge = DataGridViewHitTestTypeCloseEdge.Left; DataGridViewColumn dataGridViewColumn = null; // VS Whidbey bug 317105 - Condition unnecessary //if (hti.col != this.displayedBandsInfo.FirstDisplayedScrollingCol || this.displayedBandsInfo.LastTotallyDisplayedScrollingCol >= 0) //{ dataGridViewColumn = this.Columns.GetPreviousColumn(this.Columns[hti.col], DataGridViewElementStates.Visible, DataGridViewElementStates.None); //} if (dataGridViewColumn != null) { hti.adjacentCol = dataGridViewColumn.Index; if (this.RightToLeftInternal) { hti.mouseBarOffset = xColumnLeftEdge - x + 1; } else { hti.mouseBarOffset = xColumnLeftEdge - x - 1; } if (dataGridViewColumn.Resizable == DataGridViewTriState.True && (dataGridViewColumn.InheritedAutoSizeMode == DataGridViewAutoSizeColumnMode.None || dataGridViewColumn.InheritedAutoSizeMode == DataGridViewAutoSizeColumnMode.Fill)) { hti.typeInternal = DataGridViewHitTestTypeInternal.ColumnResizeLeft; } else { hti.typeInternal = DataGridViewHitTestTypeInternal.ColumnHeaderLeft; } } else { if (this.RowHeadersVisible && this.RowHeadersWidthSizeMode == DataGridViewRowHeadersWidthSizeMode.EnableResizing) { hti.typeInternal = DataGridViewHitTestTypeInternal.TopLeftHeaderResizeRight; if (this.RightToLeftInternal) { hti.mouseBarOffset = xColumnLeftEdge - x; } else { hti.mouseBarOffset = xColumnLeftEdge - x - 1; } } else { hti.typeInternal = DataGridViewHitTestTypeInternal.FirstColumnHeaderLeft; } } } else if (this.layout.ColumnHeaders.Bottom - y < DATAGRIDVIEW_rowSizingHotZone) { //hti.edge = DataGridViewHitTestTypeCloseEdge.Bottom; if (/*!this.RowHeadersVisible &&*/ this.ColumnHeadersHeightSizeMode == DataGridViewColumnHeadersHeightSizeMode.EnableResizing) { hti.typeInternal = DataGridViewHitTestTypeInternal.ColumnHeadersResizeBottom; hti.mouseBarOffset = this.layout.ColumnHeaders.Bottom - y - 1; } } } // check for row resize if (this.layout.RowHeaders.Contains(x, y)) { int yRowTopEdge; hti.row = GetRowIndexFromY(y, out yRowTopEdge); if (hti.row < 0) { return HitTestInfo.Nowhere; } Debug.Assert(yRowTopEdge == GetRowYFromIndex(hti.row)); hti.type = DataGridViewHitTestType.RowHeader; hti.typeInternal = DataGridViewHitTestTypeInternal.RowHeader; hti.rowStart = yRowTopEdge; if (this.RightToLeftInternal) { hti.colStart = this.layout.RowHeaders.Right-1; } else { hti.colStart = this.layout.RowHeaders.Left; } int rowHeight = this.Rows.SharedRow(hti.row).GetHeight(hti.row); if (yRowTopEdge + rowHeight - y < DATAGRIDVIEW_rowSizingHotZone) { //hti.edge = DataGridViewHitTestTypeCloseEdge.Bottom; if (RowIsResizable(hti.row) && this.AutoSizeRowsMode == DataGridViewAutoSizeRowsMode.None) { hti.typeInternal = DataGridViewHitTestTypeInternal.RowResizeBottom; hti.mouseBarOffset = yRowTopEdge + rowHeight - y - 1; } } else if (y - yRowTopEdge < DATAGRIDVIEW_rowSizingHotZone) { //hti.edge = DataGridViewHitTestTypeCloseEdge.Top; int indexTmp = -1; if (hti.row != this.displayedBandsInfo.FirstDisplayedScrollingRow || this.displayedBandsInfo.NumDisplayedFrozenRows > 0) { indexTmp = this.Rows.GetPreviousRow(hti.row, DataGridViewElementStates.Visible); } if (indexTmp != -1) { if (RowIsResizable(indexTmp) && this.AutoSizeRowsMode == DataGridViewAutoSizeRowsMode.None) { hti.typeInternal = DataGridViewHitTestTypeInternal.RowResizeTop; hti.adjacentRow = indexTmp; hti.mouseBarOffset = yRowTopEdge - y - 1; } } else { if (this.ColumnHeadersVisible && this.ColumnHeadersHeightSizeMode == DataGridViewColumnHeadersHeightSizeMode.EnableResizing) { hti.typeInternal = DataGridViewHitTestTypeInternal.TopLeftHeaderResizeBottom; hti.mouseBarOffset = yRowTopEdge - y - 1; } } } else if ((!this.RightToLeftInternal && this.layout.RowHeaders.Right - x < DATAGRIDVIEW_columnSizingHotZone) || (this.RightToLeftInternal && x - this.layout.RowHeaders.Left < DATAGRIDVIEW_columnSizingHotZone)) { //hti.edge = DataGridViewHitTestTypeCloseEdge.Right; if (this.RowHeadersWidthSizeMode == DataGridViewRowHeadersWidthSizeMode.EnableResizing) { hti.typeInternal = DataGridViewHitTestTypeInternal.RowHeadersResizeRight; if (this.RightToLeftInternal) { hti.mouseBarOffset = this.layout.RowHeaders.Left - x - 1; } else { hti.mouseBarOffset = this.layout.RowHeaders.Right - x - 1; } } } } if (this.layout.Data.Contains(x, y)) { int xColumnLeftEdge, yRowTopEdge; hti.col = GetColumnIndexFromX(x, out xColumnLeftEdge); hti.row = GetRowIndexFromY(y, out yRowTopEdge); if (hti.col < 0 || hti.row < 0) { return HitTestInfo.Nowhere; } Debug.Assert(xColumnLeftEdge == GetColumnXFromIndex(hti.col)); Debug.Assert(yRowTopEdge == GetRowYFromIndex(hti.row)); hti.type = DataGridViewHitTestType.Cell; hti.typeInternal = DataGridViewHitTestTypeInternal.Cell; hti.rowStart = yRowTopEdge; hti.colStart = xColumnLeftEdge; if (!this.ColumnHeadersVisible) { int columnWidth = this.Columns[hti.col].Thickness; if ((!this.RightToLeftInternal && xColumnLeftEdge + columnWidth - x < DATAGRIDVIEW_columnSizingHotZone) || (this.RightToLeftInternal && x - xColumnLeftEdge + columnWidth < DATAGRIDVIEW_columnSizingHotZone)) { if (this.RightToLeftInternal) { hti.mouseBarOffset = xColumnLeftEdge - columnWidth - x + 1; } else { hti.mouseBarOffset = xColumnLeftEdge + columnWidth - x - 1; } DataGridViewColumn dataGridViewColumn = this.Columns[hti.col]; if (dataGridViewColumn.Resizable == DataGridViewTriState.True && (dataGridViewColumn.InheritedAutoSizeMode == DataGridViewAutoSizeColumnMode.None || dataGridViewColumn.InheritedAutoSizeMode == DataGridViewAutoSizeColumnMode.Fill)) { hti.typeInternal = DataGridViewHitTestTypeInternal.ColumnResizeRight; } return hti; } else if ((!this.RightToLeftInternal && x - xColumnLeftEdge < DATAGRIDVIEW_columnSizingHotZone) || (this.RightToLeftInternal && xColumnLeftEdge - x < DATAGRIDVIEW_columnSizingHotZone)) { DataGridViewColumn dataGridViewColumn = null; if (hti.col != this.displayedBandsInfo.FirstDisplayedScrollingCol || this.displayedBandsInfo.LastTotallyDisplayedScrollingCol >= 0) { dataGridViewColumn = this.Columns.GetPreviousColumn(this.Columns[hti.col], DataGridViewElementStates.Visible, DataGridViewElementStates.None); } if (dataGridViewColumn != null) { hti.adjacentCol = dataGridViewColumn.Index; if (this.RightToLeftInternal) { hti.mouseBarOffset = xColumnLeftEdge - x + 1; } else { hti.mouseBarOffset = xColumnLeftEdge - x - 1; } if (dataGridViewColumn.Resizable == DataGridViewTriState.True && (dataGridViewColumn.InheritedAutoSizeMode == DataGridViewAutoSizeColumnMode.None || dataGridViewColumn.InheritedAutoSizeMode == DataGridViewAutoSizeColumnMode.Fill)) { hti.typeInternal = DataGridViewHitTestTypeInternal.ColumnResizeLeft; } return hti; } else { if (this.RowHeadersVisible && this.RowHeadersWidthSizeMode == DataGridViewRowHeadersWidthSizeMode.EnableResizing) { hti.typeInternal = DataGridViewHitTestTypeInternal.RowHeadersResizeLeft; if (this.RightToLeftInternal) { hti.mouseBarOffset = xColumnLeftEdge - x; } else { hti.mouseBarOffset = xColumnLeftEdge - x - 1; } return hti; } } } } else if ((!this.RightToLeftInternal && x - xColumnLeftEdge < DATAGRIDVIEW_columnSizingHotZone) || (this.RightToLeftInternal && xColumnLeftEdge - x < DATAGRIDVIEW_columnSizingHotZone)) { DataGridViewColumn dataGridViewColumn = this.Columns.GetFirstColumn(DataGridViewElementStates.Visible); Debug.Assert(dataGridViewColumn != null); if (hti.col == dataGridViewColumn.Index && this.RowHeadersVisible && this.RowHeadersWidthSizeMode == DataGridViewRowHeadersWidthSizeMode.EnableResizing) { hti.typeInternal = DataGridViewHitTestTypeInternal.RowHeadersResizeLeft; if (this.RightToLeftInternal) { hti.mouseBarOffset = xColumnLeftEdge - x; } else { hti.mouseBarOffset = xColumnLeftEdge - x - 1; } return hti; } } if (!this.RowHeadersVisible) { int rowHeight = this.Rows.SharedRow(hti.row).GetHeight(hti.row); if (yRowTopEdge + rowHeight - y < DATAGRIDVIEW_rowSizingHotZone) { if (RowIsResizable(hti.row) && this.AutoSizeRowsMode == DataGridViewAutoSizeRowsMode.None) { hti.typeInternal = DataGridViewHitTestTypeInternal.RowResizeBottom; hti.mouseBarOffset = yRowTopEdge + rowHeight - y - 1; } } else if (y - yRowTopEdge < DATAGRIDVIEW_rowSizingHotZone) { int indexTmp = -1; if (hti.row != this.displayedBandsInfo.FirstDisplayedScrollingRow || this.displayedBandsInfo.NumDisplayedFrozenRows > 0) { indexTmp = this.Rows.GetPreviousRow(hti.row, DataGridViewElementStates.Visible); } if (indexTmp != -1) { if (RowIsResizable(indexTmp) && this.AutoSizeRowsMode == DataGridViewAutoSizeRowsMode.None) { hti.typeInternal = DataGridViewHitTestTypeInternal.RowResizeTop; hti.adjacentRow = indexTmp; hti.mouseBarOffset = yRowTopEdge - y - 1; } } else { if (this.ColumnHeadersVisible && this.ColumnHeadersHeightSizeMode == DataGridViewColumnHeadersHeightSizeMode.EnableResizing) { hti.typeInternal = DataGridViewHitTestTypeInternal.ColumnHeadersResizeTop; hti.mouseBarOffset = yRowTopEdge - y - 1; } } } } else if (y - yRowTopEdge < DATAGRIDVIEW_rowSizingHotZone) { int rowIndex = this.Rows.GetFirstRow(DataGridViewElementStates.Visible); Debug.Assert(rowIndex >= 0); if (hti.row == rowIndex && this.ColumnHeadersVisible && this.ColumnHeadersHeightSizeMode == DataGridViewColumnHeadersHeightSizeMode.EnableResizing) { hti.typeInternal = DataGridViewHitTestTypeInternal.ColumnHeadersResizeTop; hti.mouseBarOffset = yRowTopEdge - y - 1; } } } return hti; }
private void OnColumnSelectMouseMove(HitTestInfo hti) { Debug.Assert(hti.col >= 0); Debug.Assert(this.MultiSelect); if (this.ptCurrentCell.X != -1 && hti.col != this.ptCurrentCell.X && !CommitEditForOperation(hti.col, this.ptCurrentCell.Y, true)) { // Return silently if validating/commit/abort failed return; } if (IsColumnOutOfBounds(hti.col)) { return; } this.noSelectionChangeCount++; try { if (this.trackColumnEdge >= 0 && (this.Columns.DisplayInOrder(this.trackColumn, this.trackColumnEdge) || this.trackColumnEdge == this.trackColumn) && this.Columns.DisplayInOrder(this.trackColumnEdge, hti.col)) { DataGridViewColumn dataGridViewColumn = this.Columns.GetNextColumn(this.Columns[this.trackColumnEdge], DataGridViewElementStates.Visible, DataGridViewElementStates.None); Debug.Assert(dataGridViewColumn != null); SelectColumnRange(dataGridViewColumn.Index, hti.col, true); this.trackColumnEdge = hti.col; } else if (this.trackColumnEdge >= 0 && this.Columns.DisplayInOrder(this.trackColumn, this.trackColumnEdge) && this.Columns.DisplayInOrder(hti.col, this.trackColumnEdge) && (this.Columns.DisplayInOrder(this.trackColumn, hti.col) || hti.col == this.trackColumn)) { DataGridViewColumn dataGridViewColumn = this.Columns.GetNextColumn(this.Columns[hti.col], DataGridViewElementStates.Visible, DataGridViewElementStates.None); Debug.Assert(dataGridViewColumn != null); SelectColumnRange(dataGridViewColumn.Index, this.trackColumnEdge, false); this.trackColumnEdge = hti.col; } else if (this.trackColumnEdge == -1 && this.Columns.DisplayInOrder(this.trackColumn, hti.col)) { DataGridViewColumn dataGridViewColumn = this.Columns.GetNextColumn(this.Columns[this.trackColumn], DataGridViewElementStates.Visible, DataGridViewElementStates.None); Debug.Assert(dataGridViewColumn != null); SelectColumnRange(dataGridViewColumn.Index, hti.col, true); this.trackColumnEdge = hti.col; } else if (this.trackColumnEdge >= 0 && (this.Columns.DisplayInOrder(this.trackColumnEdge, this.trackColumn) || this.trackColumnEdge == this.trackColumn) && this.Columns.DisplayInOrder(hti.col, this.trackColumnEdge)) { DataGridViewColumn dataGridViewColumn = this.Columns.GetPreviousColumn(this.Columns[this.trackColumnEdge], DataGridViewElementStates.Visible, DataGridViewElementStates.None); Debug.Assert(dataGridViewColumn != null); SelectColumnRange(hti.col, dataGridViewColumn.Index, true); this.trackColumnEdge = hti.col; } else if (this.trackColumnEdge >= 0 && this.Columns.DisplayInOrder(this.trackColumnEdge, this.trackColumn) && this.Columns.DisplayInOrder(this.trackColumnEdge, hti.col) && (this.Columns.DisplayInOrder(hti.col, this.trackColumn) || hti.col == this.trackColumn)) { DataGridViewColumn dataGridViewColumn = this.Columns.GetPreviousColumn(this.Columns[hti.col], DataGridViewElementStates.Visible, DataGridViewElementStates.None); Debug.Assert(dataGridViewColumn != null); SelectColumnRange(this.trackColumnEdge, dataGridViewColumn.Index, false); this.trackColumnEdge = hti.col; } else if (this.trackColumnEdge == -1 && this.Columns.DisplayInOrder(hti.col, this.trackColumn)) { DataGridViewColumn dataGridViewColumn = this.Columns.GetPreviousColumn(this.Columns[this.trackColumn], DataGridViewElementStates.Visible, DataGridViewElementStates.None); Debug.Assert(dataGridViewColumn != null); SelectColumnRange(hti.col, dataGridViewColumn.Index, true); this.trackColumnEdge = hti.col; } else if (this.trackColumnEdge >= 0 && this.Columns.DisplayInOrder(this.trackColumn, this.trackColumnEdge) && this.Columns.DisplayInOrder(hti.col, this.trackColumn)) { DataGridViewColumn dataGridViewColumn = this.Columns.GetNextColumn(this.Columns[this.trackColumn], DataGridViewElementStates.Visible, DataGridViewElementStates.None); Debug.Assert(dataGridViewColumn != null); SelectColumnRange(dataGridViewColumn.Index, this.trackColumnEdge, false); dataGridViewColumn = this.Columns.GetPreviousColumn(this.Columns[this.trackColumn], DataGridViewElementStates.Visible, DataGridViewElementStates.None); Debug.Assert(dataGridViewColumn != null); SelectColumnRange(hti.col, dataGridViewColumn.Index, true); this.trackColumnEdge = hti.col; } else if (this.trackColumnEdge >= 0 && this.Columns.DisplayInOrder(this.trackColumn, hti.col) && this.Columns.DisplayInOrder(this.trackColumnEdge, this.trackColumn)) { DataGridViewColumn dataGridViewColumn = this.Columns.GetPreviousColumn(this.Columns[this.trackColumn], DataGridViewElementStates.Visible, DataGridViewElementStates.None); Debug.Assert(dataGridViewColumn != null); SelectColumnRange(this.trackColumnEdge, dataGridViewColumn.Index, false); dataGridViewColumn = this.Columns.GetNextColumn(this.Columns[this.trackColumn], DataGridViewElementStates.Visible, DataGridViewElementStates.None); Debug.Assert(dataGridViewColumn != null); SelectColumnRange(dataGridViewColumn.Index, hti.col, true); this.trackColumnEdge = hti.col; } } finally { this.NoSelectionChangeCount--; } if (this.ptCurrentCell.X != -1 && hti.col != this.ptCurrentCell.X) { if (this.ptCurrentCell.Y == -1 || IsColumnOutOfBounds(hti.col)) { return; } bool success = SetCurrentCellAddressCore(hti.col, this.ptCurrentCell.Y, false /*setAnchorCellAddress*/, false /*validateCurrentCell*/, false /*throughMouseClick*/); Debug.Assert(success); } }
private bool ColumnRelocationTarget(MouseEventArgs e, HitTestInfo hti, out int previousColumnIndex) { previousColumnIndex = -1; if ((((hti.typeInternal == DataGridViewHitTestTypeInternal.ColumnHeadersResizeBottom) || (hti.typeInternal == DataGridViewHitTestTypeInternal.ColumnHeader)) || ((hti.typeInternal == DataGridViewHitTestTypeInternal.ColumnResizeLeft) || (hti.typeInternal == DataGridViewHitTestTypeInternal.ColumnResizeRight))) || ((hti.typeInternal == DataGridViewHitTestTypeInternal.ColumnHeaderLeft) || (hti.typeInternal == DataGridViewHitTestTypeInternal.ColumnHeaderRight))) { if ((hti.typeInternal == DataGridViewHitTestTypeInternal.ColumnHeadersResizeBottom) || (hti.typeInternal == DataGridViewHitTestTypeInternal.ColumnHeader)) { int columnXFromIndex = this.GetColumnXFromIndex(hti.col); int width = this.Columns[hti.col].Width; if ((this.RightToLeftInternal && (e.X < (columnXFromIndex - (width / 2)))) || (!this.RightToLeftInternal && (e.X > (columnXFromIndex + (width / 2))))) { previousColumnIndex = hti.col; } else { DataGridViewColumn column = this.Columns.GetPreviousColumn(this.Columns[hti.col], DataGridViewElementStates.Visible, DataGridViewElementStates.None); if (column != null) { previousColumnIndex = column.Index; } } } else { previousColumnIndex = ((hti.typeInternal == DataGridViewHitTestTypeInternal.ColumnResizeRight) || (hti.typeInternal == DataGridViewHitTestTypeInternal.ColumnHeaderRight)) ? hti.col : hti.adjacentCol; } DataGridViewColumn column2 = null; if (previousColumnIndex != -1) { column2 = this.Columns.GetNextColumn(this.Columns[previousColumnIndex], DataGridViewElementStates.Visible, DataGridViewElementStates.None); } if (((this.trackColumn != previousColumnIndex) && ((previousColumnIndex != -1) || (hti.col != this.trackColumn))) && ((column2 == null) || (this.trackColumn != column2.Index))) { return true; } } else if (((hti.typeInternal == DataGridViewHitTestTypeInternal.FirstColumnHeaderLeft) || (hti.typeInternal == DataGridViewHitTestTypeInternal.TopLeftHeaderResizeRight)) && (hti.col != this.trackColumn)) { return true; } return false; }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); moveHitInfo = HitTest(e.X, e.Y); switch (moveHitInfo.type) { case HitTestType.Hex: case HitTestType.Char: Cursor = Cursors.IBeam; break; default: Cursor = Cursors.Default; break; } switch (downHitInfo.type) { case HitTestType.Hex: case HitTestType.Char: if (moveHitInfo.type == downHitInfo.type) { SelectData(downHitInfo.row * 16 + downHitInfo.col, moveHitInfo.row * 16 + moveHitInfo.col); } else { SelectData(downHitInfo.row * 16 + downHitInfo.col, moveHitInfo.row * 16 + (downHitInfo.x > moveHitInfo.x ? 0 : 16)); } break; } }
/// <summary> /// ��ý�������λ�����ڵ�������Ϣ /// </summary> /// <param name="x">��������</param> /// <param name="y">��������</param> /// <returns>��������λ�����ڵ�������Ϣ</returns> public HitTestInfo HitTest(int x, int y) { x -= 2; HitTestInfo info = new HitTestInfo(); info.y = (y + itemHeight * topOffset) / itemHeight; info.x = (x + itemWidth * leftOffset + itemWidth / 2) / itemWidth; info.row = info.y; if (horizScrollBar != null && horizScrollBar.Visible && horizScrollBar.Bounds.Contains(x, y)) { info.type = HitTestType.HorizontalScrollBar; return info; } if (vertScrollBar != null && vertScrollBar.Visible && vertScrollBar.Bounds.Contains(x, y)) { info.type = HitTestType.VerticalScrollBar; return info; } if (vertScrollBar != null && vertScrollBar.Visible && horizScrollBar != null && horizScrollBar.Visible && new Rectangle(ClientSize.Width - vertScrollBar.Width, ClientSize.Height - horizScrollBar.Height, vertScrollBar.Width, horizScrollBar.Height).Contains(x, y)) return info; if (info.x >= 0 && info.x <= 7) { info.type = HitTestType.Address; } else if (info.x >= 8 && info.x <= 9) { info.type = HitTestType.Bookmark; } else if (info.x >= 10 && info.x <= 58) { info.type = HitTestType.Hex; if (info.x >= 10 && info.x <= 33) info.col = (info.x - 10) / 3; else if (info.x >= 34 && info.x <= 35) info.col = 8; else if (info.x >= 36 && info.x <= 58) info.col = (info.x - 11) / 3; } else if (info.x >= 60 && info.x <= 76) { info.type = HitTestType.Char; info.col = Math.Min(15, info.x - 60); } switch (info.type) { case HitTestType.Char: case HitTestType.Hex: if (info.row * 16 + info.col > memoryStream.Length) { Point vPoint = CoordinateFromPosistion((int)memoryStream.Length); info.col = vPoint.X; info.row = vPoint.Y; } break; } return info; }
private void EndColumnRelocation(MouseEventArgs e, HitTestInfo hti) { try { int num; if (this.lastHeaderShadow != -1) { this.dataGridViewState2[0x400] = false; this.trackColumnEdge = -1; this.lastHeaderShadow = -1; base.Invalidate(Rectangle.Union(this.layout.TopLeftHeader, this.layout.ColumnHeaders)); } if (this.ColumnRelocationTarget(e, hti, out num)) { if (num == -1) { this.Columns[this.trackColumn].DisplayIndex = 0; } else if (this.Columns[this.trackColumn].DisplayIndex > this.Columns[num].DisplayIndex) { this.Columns[this.trackColumn].DisplayIndex = this.Columns[num].DisplayIndex + 1; } else { this.Columns[this.trackColumn].DisplayIndex = this.Columns[num].DisplayIndex; } } } finally { this.RealeaseMouse(); } }
private void OnRowHeaderMouseDown(HitTestInfo hti, bool isShiftDown, bool isControlDown) { Debug.Assert(hti.Type == DataGridViewHitTestType.RowHeader); this.noSelectionChangeCount++; try { switch (this.SelectionMode) { case DataGridViewSelectionMode.CellSelect: case DataGridViewSelectionMode.FullColumnSelect: case DataGridViewSelectionMode.ColumnHeaderSelect: break; case DataGridViewSelectionMode.FullRowSelect: case DataGridViewSelectionMode.RowHeaderSelect: { bool select = true; if (isControlDown && ((this.Rows.GetRowState(hti.row) & DataGridViewElementStates.Selected) != 0)) { select = false; } if (select) { DataGridViewColumn dataGridViewColumn = this.Columns.GetFirstColumn(DataGridViewElementStates.Visible); if (dataGridViewColumn != null && hti.row != this.ptCurrentCell.Y) { int oldCurrentCellX = this.ptCurrentCell.X; int oldCurrentCellY = this.ptCurrentCell.Y; // Make sure we will be able to scroll into view if (!EndEdit(DataGridViewDataErrorContexts.Parsing | DataGridViewDataErrorContexts.Commit | DataGridViewDataErrorContexts.CurrentCellChange, DataGridViewValidateCellInternal.Always /*validateCell*/, true /*fireCellLeave*/, true /*fireCellEnter*/, hti.row != this.ptCurrentCell.Y /*fireRowLeave*/, hti.row != this.ptCurrentCell.Y /*fireRowEnter*/, false /*fireLeave*/, this.EditMode != DataGridViewEditMode.EditOnEnter /*keepFocus*/, true /*resetCurrentCell*/, false /*resetAnchorCell*/)) { // Just cancel operation silently instead of throwing InvalidOperationException return; } if (oldCurrentCellY != -1) { DataGridViewCell dataGridViewCellTmp = null; if (IsInnerCellOutOfBounds(oldCurrentCellX, oldCurrentCellY)) { return; } if (OnRowValidating(ref dataGridViewCellTmp, oldCurrentCellX, oldCurrentCellY)) { // Row validation was cancelled if (IsInnerCellOutOfBounds(oldCurrentCellX, oldCurrentCellY)) { return; } OnRowEnter(ref dataGridViewCellTmp, oldCurrentCellX, oldCurrentCellY, true /*canCreateNewRow*/, true /*validationFailureOccurred*/); if (IsInnerCellOutOfBounds(oldCurrentCellX, oldCurrentCellY)) { return; } OnCellEnter(ref dataGridViewCellTmp, oldCurrentCellX, oldCurrentCellY); return; } if (IsInnerCellOutOfBounds(oldCurrentCellX, oldCurrentCellY)) { return; } OnRowValidated(ref dataGridViewCellTmp, oldCurrentCellX, oldCurrentCellY); // Row validation was not cancelled, but operation needs to be re-evaluated. if (hti.row >= this.Rows.Count) { int lastVisibleRowIndex = this.Rows.GetLastRow(DataGridViewElementStates.Visible); if (this.ptCurrentCell.X == -1 && lastVisibleRowIndex != -1) { // CurrentCell was reset because commit deleted row(s). // Since the user wants to select a row, we don't want to // end up with no CurrentCell. We pick the last visible // row in the grid which may be the 'new row'. if (IsColumnOutOfBounds(oldCurrentCellX)) { return; } bool success = SetAndSelectCurrentCellAddress(oldCurrentCellX, lastVisibleRowIndex, true, false, false, false /*clearSelection*/, false /*forceCurrentCellSelection*/); Debug.Assert(success); } return; } else if ((this.Rows.GetRowState(hti.row) & DataGridViewElementStates.Visible) == 0) { return; } } } bool selectRowRange = false; this.trackRow = hti.row; this.trackRowEdge = -1; if (this.MultiSelect && isShiftDown && this.ptAnchorCell.Y > -1 && (this.Rows.GetRowState(this.ptAnchorCell.Y) & DataGridViewElementStates.Selected) != 0) { selectRowRange = true; } if (!this.MultiSelect || !isControlDown || isShiftDown) { Debug.Assert(this.MultiSelect || this.selectedBandIndexes.Count <= 1); int bandIndex = 0; bool switchedToBulkPaint = false; if (this.selectedBandIndexes.Count > DATAGRIDVIEW_bulkPaintThreshold) { this.inBulkPaintCount++; switchedToBulkPaint = true; } try { while (bandIndex < this.selectedBandIndexes.Count) { if (this.selectedBandIndexes[bandIndex] != hti.row) { // deselect currently selected row SetSelectedRowCore(this.selectedBandIndexes[bandIndex], false); } else { bandIndex++; } } if (this.SelectionMode == DataGridViewSelectionMode.RowHeaderSelect) { RemoveIndividuallySelectedCells(); } else { Debug.Assert(this.individualSelectedCells.Count == 0); } } finally { if (switchedToBulkPaint) { ExitBulkPaint(-1, -1); } } } if (this.MultiSelect && this.dataGridViewOper[DATAGRIDVIEWOPER_trackMouseMoves]) { this.dataGridViewOper[DATAGRIDVIEWOPER_trackRowSelect] = true; } if (selectRowRange) { if (hti.row >= this.ptAnchorCell.Y) { SelectRowRange(this.ptAnchorCell.Y, hti.row, true); } else { SelectRowRange(hti.row, this.ptAnchorCell.Y, true); } } else if ((this.Rows.GetRowState(hti.row) & DataGridViewElementStates.Selected) == 0) { Debug.Assert(this.selectedBandIndexes.Contains(hti.row) == ((this.Rows.GetRowState(hti.row) & DataGridViewElementStates.Selected) != 0)); SetSelectedRowCore(hti.row, true); } if (dataGridViewColumn != null) { if (hti.row != this.ptCurrentCell.Y) { if (IsInnerCellOutOfBounds(dataGridViewColumn.Index, hti.row)) { return; } // set current cell to the left most visible cell in the row bool success = ScrollIntoView(dataGridViewColumn.Index, hti.row, false); Debug.Assert(success); if (IsInnerCellOutOfBounds(dataGridViewColumn.Index, hti.row)) { return; } success = SetCurrentCellAddressCore(dataGridViewColumn.Index, hti.row, !selectRowRange, false, true); Debug.Assert(success); } else if (-1 != this.ptCurrentCell.Y) { // Potentially have to give focus back to the current edited cell. bool success = SetCurrentCellAddressCore(this.ptCurrentCell.X, this.ptCurrentCell.Y, false /*setAnchorCellAddress*/, false /*validateCurrentCell*/, false /*throughMouseClick*/); Debug.Assert(success); } } else { Debug.Assert(this.CurrentCellAddress == new Point(-1, -1)); } } else { Debug.Assert(this.selectedBandIndexes.Contains(hti.row)); SetSelectedRowCore(hti.row, false); } break; } } } finally { this.NoSelectionChangeCount--; } }
// selects the clicked date private void DoDateMouseDown (HitTestInfo hti) { SetItemClick(hti); }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (!Focused && CanFocus) Focus(); if (e.Button != MouseButtons.Left) return; downHitInfo = HitTest(e.X, e.Y); switch (downHitInfo.type) { case HitTestType.Hex: case HitTestType.Char: colType = downHitInfo.type; selLength = 0; selStart = downHitInfo.row * 16 + downHitInfo.col; endCaret = false; modifyHex = '\x00'; if (SelectionChanged != null) SelectionChanged(this, EventArgs.Empty); UpdateCaret(); Invalidate(); break; case HitTestType.Bookmark: if (bookmarks.Contains(downHitInfo.row)) bookmarks.Remove(downHitInfo.row); else bookmarks.Add(downHitInfo.row); Invalidate(); break; } }
private void OnRowSelectMouseMove(HitTestInfo hti) { Debug.Assert(hti.row >= 0); Debug.Assert(this.MultiSelect); if (this.ptCurrentCell.Y != -1 && hti.row != this.ptCurrentCell.Y && !CommitEditForOperation(this.ptCurrentCell.X, hti.row, true)) { // Return silently if validating/commit/abort failed return; } if (IsRowOutOfBounds(hti.row)) { return; } this.noSelectionChangeCount++; try { if (this.trackRowEdge >= this.trackRow && hti.row > this.trackRowEdge && this.trackRowEdge >= 0) { SelectRowRange(this.Rows.GetNextRow(this.trackRowEdge, DataGridViewElementStates.Visible), hti.row, true); this.trackRowEdge = hti.row; } else if (this.trackRowEdge > this.trackRow && hti.row < this.trackRowEdge && hti.row >= this.trackRow && this.trackRowEdge >= 0) { SelectRowRange(this.Rows.GetNextRow(hti.row, DataGridViewElementStates.Visible), this.trackRowEdge, false); this.trackRowEdge = hti.row; } else if (hti.row > this.trackRow && this.trackRowEdge == -1) { SelectRowRange(this.Rows.GetNextRow(this.trackRow, DataGridViewElementStates.Visible), hti.row, true); this.trackRowEdge = hti.row; } else if (this.trackRowEdge <= this.trackRow && hti.row < this.trackRowEdge && this.trackRowEdge >= 0) { SelectRowRange(hti.row, this.Rows.GetPreviousRow(this.trackRowEdge, DataGridViewElementStates.Visible), true); this.trackRowEdge = hti.row; } else if (this.trackRowEdge < this.trackRow && hti.row > this.trackRowEdge && hti.row <= this.trackRow && this.trackRowEdge >= 0) { SelectRowRange(this.trackRowEdge, this.Rows.GetPreviousRow(hti.row, DataGridViewElementStates.Visible), false); this.trackRowEdge = hti.row; } else if (hti.row < this.trackRow && this.trackRowEdge == -1) { SelectRowRange(hti.row, this.Rows.GetPreviousRow(this.trackRow, DataGridViewElementStates.Visible), true); this.trackRowEdge = hti.row; } else if (this.trackRowEdge > this.trackRow && hti.row < this.trackRow) { SelectRowRange(this.Rows.GetNextRow(this.trackRow, DataGridViewElementStates.Visible), this.trackRowEdge, false); SelectRowRange(hti.row, this.Rows.GetPreviousRow(this.trackRow, DataGridViewElementStates.Visible), true); this.trackRowEdge = hti.row; } else if (hti.row > this.trackRow && this.trackRowEdge < this.trackRow && this.trackRowEdge >= 0) { SelectRowRange(this.trackRowEdge, this.Rows.GetPreviousRow(this.trackRow, DataGridViewElementStates.Visible), false); SelectRowRange(this.Rows.GetNextRow(this.trackRow, DataGridViewElementStates.Visible), hti.row, true); this.trackRowEdge = hti.row; } } finally { this.NoSelectionChangeCount--; } if (this.ptCurrentCell.Y != -1 && hti.row != this.ptCurrentCell.Y) { if (IsRowOutOfBounds(hti.row)) { return; } bool success = SetCurrentCellAddressCore(this.ptCurrentCell.X, hti.row, false /*setAnchorCellAddress*/, false /*validateCurrentCell*/, false /*throughMouseClick*/); Debug.Assert(success); } }
private void SetCursorType(HitTestInfo ht) { switch ( ht.Type ) { case HitTestType.TableColumnResize: Cursor=Cursors.VSplit; break; default: Cursor=Cursors.IBeam; break; } }
private void UpdateMouseEnteredCell(HitTestInfo hti, MouseEventArgs e) { Point ptMouse = PointToClient(Control.MousePosition); HitTestInfo htiToUse; if (hti != null) { htiToUse = hti; } else { htiToUse = HitTest(ptMouse.X, ptMouse.Y); } if (htiToUse.Type != DataGridViewHitTestType.None && htiToUse.Type != DataGridViewHitTestType.HorizontalScrollBar && htiToUse.Type != DataGridViewHitTestType.VerticalScrollBar) { if (this.ptMouseEnteredCell.X != htiToUse.col || this.ptMouseEnteredCell.Y != htiToUse.row) { DataGridViewCellEventArgs dgvce; if (this.ptMouseEnteredCell.X >= -1 && this.ptMouseEnteredCell.X < this.Columns.Count && this.ptMouseEnteredCell.Y >= -1 && this.ptMouseEnteredCell.Y < this.Rows.Count) { dgvce = new DataGridViewCellEventArgs(this.ptMouseEnteredCell.X, this.ptMouseEnteredCell.Y); OnCellMouseLeave(dgvce); } dgvce = new DataGridViewCellEventArgs(htiToUse.col, htiToUse.row); OnCellMouseEnter(dgvce); } if (e != null) { int mouseX = e.X - htiToUse.ColumnX; if (this.RightToLeftInternal) { mouseX += ((htiToUse.col == -1) ? this.RowHeadersWidth : this.Columns[htiToUse.col].Thickness); } DataGridViewCellMouseEventArgs dgvcme = new DataGridViewCellMouseEventArgs(htiToUse.col, htiToUse.row, mouseX, e.Y - htiToUse.RowY, e); OnCellMouseMove(dgvcme); } } else if (this.ptMouseEnteredCell.X != -2) { if (this.ptMouseEnteredCell.X >= -1 && this.ptMouseEnteredCell.X < this.Columns.Count && this.ptMouseEnteredCell.Y >= -1 && this.ptMouseEnteredCell.Y < this.Rows.Count) { DataGridViewCellEventArgs dgvce = new DataGridViewCellEventArgs(this.ptMouseEnteredCell.X, this.ptMouseEnteredCell.Y); OnCellMouseLeave(dgvce); } else { this.ptMouseEnteredCell.X = this.ptMouseEnteredCell.Y = -2; } } }
private bool ColumnRelocationTarget(MouseEventArgs e, HitTestInfo hti, out int previousColumnIndex) { previousColumnIndex = -1; if (hti.typeInternal == DataGridViewHitTestTypeInternal.ColumnHeadersResizeBottom || hti.typeInternal == DataGridViewHitTestTypeInternal.ColumnHeader || hti.typeInternal == DataGridViewHitTestTypeInternal.ColumnResizeLeft || hti.typeInternal == DataGridViewHitTestTypeInternal.ColumnResizeRight || hti.typeInternal == DataGridViewHitTestTypeInternal.ColumnHeaderLeft || hti.typeInternal == DataGridViewHitTestTypeInternal.ColumnHeaderRight) { Debug.Assert(hti.col != -1); if (hti.typeInternal == DataGridViewHitTestTypeInternal.ColumnHeadersResizeBottom || hti.typeInternal == DataGridViewHitTestTypeInternal.ColumnHeader) { int xColumnLeftEdge = GetColumnXFromIndex(hti.col); int wColumn = this.Columns[hti.col].Width; if ((this.RightToLeftInternal && e.X < xColumnLeftEdge - wColumn / 2) || (!this.RightToLeftInternal && e.X > xColumnLeftEdge + wColumn / 2)) { // Insert column on the right of hti.col previousColumnIndex = hti.col; } else { // Insert column on the left of hti.col DataGridViewColumn dataGridViewColumnPrev = this.Columns.GetPreviousColumn(this.Columns[hti.col], DataGridViewElementStates.Visible, DataGridViewElementStates.None); if (dataGridViewColumnPrev != null) { previousColumnIndex = dataGridViewColumnPrev.Index; } } } else { previousColumnIndex = (hti.typeInternal == DataGridViewHitTestTypeInternal.ColumnResizeRight || hti.typeInternal == DataGridViewHitTestTypeInternal.ColumnHeaderRight) ? hti.col : hti.adjacentCol; } DataGridViewColumn dataGridViewColumnNext = null; if (previousColumnIndex != -1) { dataGridViewColumnNext = this.Columns.GetNextColumn(this.Columns[previousColumnIndex], DataGridViewElementStates.Visible, DataGridViewElementStates.None); } if (this.trackColumn != previousColumnIndex && !(previousColumnIndex == -1 && hti.col == this.trackColumn) && (dataGridViewColumnNext == null || this.trackColumn != dataGridViewColumnNext.Index)) { return true; } } else if (hti.typeInternal == DataGridViewHitTestTypeInternal.FirstColumnHeaderLeft || hti.typeInternal == DataGridViewHitTestTypeInternal.TopLeftHeaderResizeRight) { Debug.Assert(hti.col != -1); if (hti.col != this.trackColumn) { return true; } } return false; }
private void EndColumnRelocation(MouseEventArgs e, HitTestInfo hti) { try { if (this.lastHeaderShadow != -1) { this.dataGridViewState2[DATAGRIDVIEWSTATE2_showColumnRelocationInsertion] = false; this.trackColumnEdge = -1; this.lastHeaderShadow = -1; Invalidate(Rectangle.Union(this.layout.TopLeftHeader, this.layout.ColumnHeaders)); } int previousColumnIndex; if (ColumnRelocationTarget(e, hti, out previousColumnIndex)) { if (previousColumnIndex == -1) { this.Columns[this.trackColumn].DisplayIndex = 0; } else if (this.Columns[this.trackColumn].DisplayIndex > this.Columns[previousColumnIndex].DisplayIndex) { this.Columns[this.trackColumn].DisplayIndex = this.Columns[previousColumnIndex].DisplayIndex + 1; } else { this.Columns[this.trackColumn].DisplayIndex = this.Columns[previousColumnIndex].DisplayIndex; } } } finally { RealeaseMouse(); } }
public HitTestInfo HitTest(int x, int y) { HitTestInfo info = new HitTestInfo(); if (this.layout.Inside.Contains(x, y)) { if (((this.horizScrollBar != null) && this.horizScrollBar.Visible) && this.horizScrollBar.Bounds.Contains(x, y)) { info.type = DataGridViewHitTestType.HorizontalScrollBar; return info; } if (((this.vertScrollBar != null) && this.vertScrollBar.Visible) && this.vertScrollBar.Bounds.Contains(x, y)) { info.type = DataGridViewHitTestType.VerticalScrollBar; return info; } if (this.layout.TopLeftHeader.Contains(x, y)) { info.type = DataGridViewHitTestType.TopLeftHeader; info.typeInternal = DataGridViewHitTestTypeInternal.TopLeftHeader; if (this.RightToLeftInternal) { info.colStart = this.layout.TopLeftHeader.Right - 1; } else { info.colStart = this.layout.TopLeftHeader.Left; } info.rowStart = this.layout.TopLeftHeader.Top; if ((!this.RightToLeftInternal && ((this.layout.TopLeftHeader.Right - x) < 6)) || (this.RightToLeftInternal && ((x - this.layout.TopLeftHeader.Left) < 6))) { if (this.RowHeadersWidthSizeMode == DataGridViewRowHeadersWidthSizeMode.EnableResizing) { info.typeInternal = DataGridViewHitTestTypeInternal.TopLeftHeaderResizeLeft; if (this.RightToLeftInternal) { info.mouseBarOffset = (this.layout.TopLeftHeader.Left - x) - 1; return info; } info.mouseBarOffset = (this.layout.TopLeftHeader.Right - x) - 1; } return info; } if ((((this.layout.TopLeftHeader.Top + this.layout.TopLeftHeader.Height) - y) < 5) && (this.ColumnHeadersHeightSizeMode == DataGridViewColumnHeadersHeightSizeMode.EnableResizing)) { info.typeInternal = DataGridViewHitTestTypeInternal.TopLeftHeaderResizeTop; info.mouseBarOffset = ((this.layout.TopLeftHeader.Top + this.layout.TopLeftHeader.Height) - y) - 1; } return info; } if (this.layout.ColumnHeaders.Contains(x, y)) { int num; info.col = this.GetColumnIndexFromX(x, out num); if (info.col < 0) { return HitTestInfo.Nowhere; } info.type = DataGridViewHitTestType.ColumnHeader; info.typeInternal = DataGridViewHitTestTypeInternal.ColumnHeader; info.rowStart = this.layout.ColumnHeaders.Top; info.colStart = num; int thickness = this.Columns[info.col].Thickness; if ((!this.RightToLeftInternal && (((num + thickness) - x) < 6)) || (this.RightToLeftInternal && (((x - num) + thickness) < 6))) { if (this.RightToLeftInternal) { info.mouseBarOffset = ((num - thickness) - x) + 1; } else { info.mouseBarOffset = ((num + thickness) - x) - 1; } DataGridViewColumn column = this.Columns[info.col]; if ((column.Resizable == DataGridViewTriState.True) && ((column.InheritedAutoSizeMode == DataGridViewAutoSizeColumnMode.None) || (column.InheritedAutoSizeMode == DataGridViewAutoSizeColumnMode.Fill))) { info.typeInternal = DataGridViewHitTestTypeInternal.ColumnResizeRight; } else { info.typeInternal = DataGridViewHitTestTypeInternal.ColumnHeaderRight; } } else if ((!this.RightToLeftInternal && ((x - num) < 6)) || (this.RightToLeftInternal && ((num - x) < 6))) { DataGridViewColumn column2 = null; column2 = this.Columns.GetPreviousColumn(this.Columns[info.col], DataGridViewElementStates.Visible, DataGridViewElementStates.None); if (column2 != null) { info.adjacentCol = column2.Index; if (this.RightToLeftInternal) { info.mouseBarOffset = (num - x) + 1; } else { info.mouseBarOffset = (num - x) - 1; } if ((column2.Resizable == DataGridViewTriState.True) && ((column2.InheritedAutoSizeMode == DataGridViewAutoSizeColumnMode.None) || (column2.InheritedAutoSizeMode == DataGridViewAutoSizeColumnMode.Fill))) { info.typeInternal = DataGridViewHitTestTypeInternal.ColumnResizeLeft; } else { info.typeInternal = DataGridViewHitTestTypeInternal.ColumnHeaderLeft; } } else if (this.RowHeadersVisible && (this.RowHeadersWidthSizeMode == DataGridViewRowHeadersWidthSizeMode.EnableResizing)) { info.typeInternal = DataGridViewHitTestTypeInternal.TopLeftHeaderResizeRight; if (this.RightToLeftInternal) { info.mouseBarOffset = num - x; } else { info.mouseBarOffset = (num - x) - 1; } } else { info.typeInternal = DataGridViewHitTestTypeInternal.FirstColumnHeaderLeft; } } else if (((this.layout.ColumnHeaders.Bottom - y) < 5) && (this.ColumnHeadersHeightSizeMode == DataGridViewColumnHeadersHeightSizeMode.EnableResizing)) { info.typeInternal = DataGridViewHitTestTypeInternal.ColumnHeadersResizeBottom; info.mouseBarOffset = (this.layout.ColumnHeaders.Bottom - y) - 1; } } if (this.layout.RowHeaders.Contains(x, y)) { int num3; info.row = this.GetRowIndexFromY(y, out num3); if (info.row < 0) { return HitTestInfo.Nowhere; } info.type = DataGridViewHitTestType.RowHeader; info.typeInternal = DataGridViewHitTestTypeInternal.RowHeader; info.rowStart = num3; if (this.RightToLeftInternal) { info.colStart = this.layout.RowHeaders.Right - 1; } else { info.colStart = this.layout.RowHeaders.Left; } int height = this.Rows.SharedRow(info.row).GetHeight(info.row); if (((num3 + height) - y) < 5) { if (this.RowIsResizable(info.row) && (this.AutoSizeRowsMode == DataGridViewAutoSizeRowsMode.None)) { info.typeInternal = DataGridViewHitTestTypeInternal.RowResizeBottom; info.mouseBarOffset = ((num3 + height) - y) - 1; } } else if ((y - num3) < 5) { int rowIndex = -1; if ((info.row != this.displayedBandsInfo.FirstDisplayedScrollingRow) || (this.displayedBandsInfo.NumDisplayedFrozenRows > 0)) { rowIndex = this.Rows.GetPreviousRow(info.row, DataGridViewElementStates.Visible); } if (rowIndex != -1) { if (this.RowIsResizable(rowIndex) && (this.AutoSizeRowsMode == DataGridViewAutoSizeRowsMode.None)) { info.typeInternal = DataGridViewHitTestTypeInternal.RowResizeTop; info.adjacentRow = rowIndex; info.mouseBarOffset = (num3 - y) - 1; } } else if (this.ColumnHeadersVisible && (this.ColumnHeadersHeightSizeMode == DataGridViewColumnHeadersHeightSizeMode.EnableResizing)) { info.typeInternal = DataGridViewHitTestTypeInternal.TopLeftHeaderResizeBottom; info.mouseBarOffset = (num3 - y) - 1; } } else if (((!this.RightToLeftInternal && ((this.layout.RowHeaders.Right - x) < 6)) || (this.RightToLeftInternal && ((x - this.layout.RowHeaders.Left) < 6))) && (this.RowHeadersWidthSizeMode == DataGridViewRowHeadersWidthSizeMode.EnableResizing)) { info.typeInternal = DataGridViewHitTestTypeInternal.RowHeadersResizeRight; if (this.RightToLeftInternal) { info.mouseBarOffset = (this.layout.RowHeaders.Left - x) - 1; } else { info.mouseBarOffset = (this.layout.RowHeaders.Right - x) - 1; } } } if (this.layout.Data.Contains(x, y)) { int num6; int num7; info.col = this.GetColumnIndexFromX(x, out num6); info.row = this.GetRowIndexFromY(y, out num7); if ((info.col < 0) || (info.row < 0)) { return HitTestInfo.Nowhere; } info.type = DataGridViewHitTestType.Cell; info.typeInternal = DataGridViewHitTestTypeInternal.Cell; info.rowStart = num7; info.colStart = num6; if (!this.ColumnHeadersVisible) { int num8 = this.Columns[info.col].Thickness; if ((!this.RightToLeftInternal && (((num6 + num8) - x) < 6)) || (this.RightToLeftInternal && (((x - num6) + num8) < 6))) { if (this.RightToLeftInternal) { info.mouseBarOffset = ((num6 - num8) - x) + 1; } else { info.mouseBarOffset = ((num6 + num8) - x) - 1; } DataGridViewColumn column3 = this.Columns[info.col]; if ((column3.Resizable == DataGridViewTriState.True) && ((column3.InheritedAutoSizeMode == DataGridViewAutoSizeColumnMode.None) || (column3.InheritedAutoSizeMode == DataGridViewAutoSizeColumnMode.Fill))) { info.typeInternal = DataGridViewHitTestTypeInternal.ColumnResizeRight; } return info; } if ((!this.RightToLeftInternal && ((x - num6) < 6)) || (this.RightToLeftInternal && ((num6 - x) < 6))) { DataGridViewColumn column4 = null; if ((info.col != this.displayedBandsInfo.FirstDisplayedScrollingCol) || (this.displayedBandsInfo.LastTotallyDisplayedScrollingCol >= 0)) { column4 = this.Columns.GetPreviousColumn(this.Columns[info.col], DataGridViewElementStates.Visible, DataGridViewElementStates.None); } if (column4 != null) { info.adjacentCol = column4.Index; if (this.RightToLeftInternal) { info.mouseBarOffset = (num6 - x) + 1; } else { info.mouseBarOffset = (num6 - x) - 1; } if ((column4.Resizable == DataGridViewTriState.True) && ((column4.InheritedAutoSizeMode == DataGridViewAutoSizeColumnMode.None) || (column4.InheritedAutoSizeMode == DataGridViewAutoSizeColumnMode.Fill))) { info.typeInternal = DataGridViewHitTestTypeInternal.ColumnResizeLeft; } return info; } if (this.RowHeadersVisible && (this.RowHeadersWidthSizeMode == DataGridViewRowHeadersWidthSizeMode.EnableResizing)) { info.typeInternal = DataGridViewHitTestTypeInternal.RowHeadersResizeLeft; if (this.RightToLeftInternal) { info.mouseBarOffset = num6 - x; return info; } info.mouseBarOffset = (num6 - x) - 1; return info; } } } else if ((!this.RightToLeftInternal && ((x - num6) < 6)) || (this.RightToLeftInternal && ((num6 - x) < 6))) { DataGridViewColumn firstColumn = this.Columns.GetFirstColumn(DataGridViewElementStates.Visible); if (((info.col == firstColumn.Index) && this.RowHeadersVisible) && (this.RowHeadersWidthSizeMode == DataGridViewRowHeadersWidthSizeMode.EnableResizing)) { info.typeInternal = DataGridViewHitTestTypeInternal.RowHeadersResizeLeft; if (this.RightToLeftInternal) { info.mouseBarOffset = num6 - x; return info; } info.mouseBarOffset = (num6 - x) - 1; return info; } } if (!this.RowHeadersVisible) { int num9 = this.Rows.SharedRow(info.row).GetHeight(info.row); if (((num7 + num9) - y) < 5) { if (this.RowIsResizable(info.row) && (this.AutoSizeRowsMode == DataGridViewAutoSizeRowsMode.None)) { info.typeInternal = DataGridViewHitTestTypeInternal.RowResizeBottom; info.mouseBarOffset = ((num7 + num9) - y) - 1; } return info; } if ((y - num7) < 5) { int previousRow = -1; if ((info.row != this.displayedBandsInfo.FirstDisplayedScrollingRow) || (this.displayedBandsInfo.NumDisplayedFrozenRows > 0)) { previousRow = this.Rows.GetPreviousRow(info.row, DataGridViewElementStates.Visible); } if (previousRow == -1) { if (this.ColumnHeadersVisible && (this.ColumnHeadersHeightSizeMode == DataGridViewColumnHeadersHeightSizeMode.EnableResizing)) { info.typeInternal = DataGridViewHitTestTypeInternal.ColumnHeadersResizeTop; info.mouseBarOffset = (num7 - y) - 1; } return info; } if (this.RowIsResizable(previousRow) && (this.AutoSizeRowsMode == DataGridViewAutoSizeRowsMode.None)) { info.typeInternal = DataGridViewHitTestTypeInternal.RowResizeTop; info.adjacentRow = previousRow; info.mouseBarOffset = (num7 - y) - 1; } } return info; } if ((y - num7) < 5) { int firstRow = this.Rows.GetFirstRow(DataGridViewElementStates.Visible); if (((info.row == firstRow) && this.ColumnHeadersVisible) && (this.ColumnHeadersHeightSizeMode == DataGridViewColumnHeadersHeightSizeMode.EnableResizing)) { info.typeInternal = DataGridViewHitTestTypeInternal.ColumnHeadersResizeTop; info.mouseBarOffset = (num7 - y) - 1; } } } } return info; }
private void OnColumnSelectMouseMove(HitTestInfo hti) { if ((((this.ptCurrentCell.X == -1) || (hti.col == this.ptCurrentCell.X)) || this.CommitEditForOperation(hti.col, this.ptCurrentCell.Y, true)) && !this.IsColumnOutOfBounds(hti.col)) { this.noSelectionChangeCount++; try { if (((this.trackColumnEdge >= 0) && (this.Columns.DisplayInOrder(this.trackColumn, this.trackColumnEdge) || (this.trackColumnEdge == this.trackColumn))) && this.Columns.DisplayInOrder(this.trackColumnEdge, hti.col)) { DataGridViewColumn column = this.Columns.GetNextColumn(this.Columns[this.trackColumnEdge], DataGridViewElementStates.Visible, DataGridViewElementStates.None); this.SelectColumnRange(column.Index, hti.col, true); this.trackColumnEdge = hti.col; } else if ((((this.trackColumnEdge >= 0) && this.Columns.DisplayInOrder(this.trackColumn, this.trackColumnEdge)) && this.Columns.DisplayInOrder(hti.col, this.trackColumnEdge)) && (this.Columns.DisplayInOrder(this.trackColumn, hti.col) || (hti.col == this.trackColumn))) { DataGridViewColumn column2 = this.Columns.GetNextColumn(this.Columns[hti.col], DataGridViewElementStates.Visible, DataGridViewElementStates.None); this.SelectColumnRange(column2.Index, this.trackColumnEdge, false); this.trackColumnEdge = hti.col; } else if ((this.trackColumnEdge == -1) && this.Columns.DisplayInOrder(this.trackColumn, hti.col)) { DataGridViewColumn column3 = this.Columns.GetNextColumn(this.Columns[this.trackColumn], DataGridViewElementStates.Visible, DataGridViewElementStates.None); this.SelectColumnRange(column3.Index, hti.col, true); this.trackColumnEdge = hti.col; } else if (((this.trackColumnEdge >= 0) && (this.Columns.DisplayInOrder(this.trackColumnEdge, this.trackColumn) || (this.trackColumnEdge == this.trackColumn))) && this.Columns.DisplayInOrder(hti.col, this.trackColumnEdge)) { DataGridViewColumn column4 = this.Columns.GetPreviousColumn(this.Columns[this.trackColumnEdge], DataGridViewElementStates.Visible, DataGridViewElementStates.None); this.SelectColumnRange(hti.col, column4.Index, true); this.trackColumnEdge = hti.col; } else if ((((this.trackColumnEdge >= 0) && this.Columns.DisplayInOrder(this.trackColumnEdge, this.trackColumn)) && this.Columns.DisplayInOrder(this.trackColumnEdge, hti.col)) && (this.Columns.DisplayInOrder(hti.col, this.trackColumn) || (hti.col == this.trackColumn))) { DataGridViewColumn column5 = this.Columns.GetPreviousColumn(this.Columns[hti.col], DataGridViewElementStates.Visible, DataGridViewElementStates.None); this.SelectColumnRange(this.trackColumnEdge, column5.Index, false); this.trackColumnEdge = hti.col; } else if ((this.trackColumnEdge == -1) && this.Columns.DisplayInOrder(hti.col, this.trackColumn)) { DataGridViewColumn column6 = this.Columns.GetPreviousColumn(this.Columns[this.trackColumn], DataGridViewElementStates.Visible, DataGridViewElementStates.None); this.SelectColumnRange(hti.col, column6.Index, true); this.trackColumnEdge = hti.col; } else if (((this.trackColumnEdge >= 0) && this.Columns.DisplayInOrder(this.trackColumn, this.trackColumnEdge)) && this.Columns.DisplayInOrder(hti.col, this.trackColumn)) { DataGridViewColumn column7 = this.Columns.GetNextColumn(this.Columns[this.trackColumn], DataGridViewElementStates.Visible, DataGridViewElementStates.None); this.SelectColumnRange(column7.Index, this.trackColumnEdge, false); column7 = this.Columns.GetPreviousColumn(this.Columns[this.trackColumn], DataGridViewElementStates.Visible, DataGridViewElementStates.None); this.SelectColumnRange(hti.col, column7.Index, true); this.trackColumnEdge = hti.col; } else if (((this.trackColumnEdge >= 0) && this.Columns.DisplayInOrder(this.trackColumn, hti.col)) && this.Columns.DisplayInOrder(this.trackColumnEdge, this.trackColumn)) { DataGridViewColumn column8 = this.Columns.GetPreviousColumn(this.Columns[this.trackColumn], DataGridViewElementStates.Visible, DataGridViewElementStates.None); this.SelectColumnRange(this.trackColumnEdge, column8.Index, false); column8 = this.Columns.GetNextColumn(this.Columns[this.trackColumn], DataGridViewElementStates.Visible, DataGridViewElementStates.None); this.SelectColumnRange(column8.Index, hti.col, true); this.trackColumnEdge = hti.col; } } finally { this.NoSelectionChangeCount--; } if (((this.ptCurrentCell.X != -1) && (hti.col != this.ptCurrentCell.X)) && ((this.ptCurrentCell.Y != -1) && !this.IsColumnOutOfBounds(hti.col))) { this.SetCurrentCellAddressCore(hti.col, this.ptCurrentCell.Y, false, false, false); } } }