public void DataGridCell_Equals_Invoke_ReturnsExpected(DataGridCell cell, object other, bool expected) { if (other is DataGridCell otherCell) { Assert.Equal(expected, cell.GetHashCode().Equals(otherCell.GetHashCode())); } Assert.Equal(expected, cell.Equals(other)); }
private void ShowToolTipForCurrentCell(int x, int y) { HitTestInfo hitInfo = HitTest(x, y); Debug.Assert(hitInfo != null, "hitInfo != null"); string cellText = string.Empty; bool overSameCell = false; if (hitInfo.Type == HitTestType.Cell) { DataGridCell hitCell = new DataGridCell(hitInfo.Row, hitInfo.Column); overSameCell = hitCell.Equals(m_lastToolTipCell); m_lastToolTipCell = hitCell; // Get the column style and text for the cell under the mouse pointer. DataGridTableStyle tableStyle = CurrentTableStyle; if (tableStyle != null) { DataGridColumnStyle columnStyle = tableStyle.GridColumnStyles[hitCell.ColumnNumber]; ICellToolTip tooltipColumn = columnStyle as ICellToolTip; if (tooltipColumn != null) { // This column can provide its own tool tip. Make the hit coordinates relative to the cell. Rectangle cellBounds = GetCellBounds(hitCell); cellText = tooltipColumn.GetCellToolTip(x - cellBounds.X, y - cellBounds.Y, CurrencyManager, hitCell); } if (tooltipColumn == null || (ShowToolTipsForTextColumns && cellText == null)) { System.Windows.Forms.DataGridTextBoxColumn textColumn = columnStyle as System.Windows.Forms.DataGridTextBoxColumn; if (textColumn != null) { cellText = GetToolTipForTextColumn(x, y, hitCell, textColumn); } } } } else { m_lastToolTipCell = new DataGridCell(-1, -1); } // If the tooltip text hasn't changed AND the mouse is over the same cell as before then // don't make any changes. This check has to be made - if SetToolTip() is called whenever the mouse // moves then no tooltip is displayed at all! If we check only for the same cell this doesn't allow // for column styles like DataGridEditorColumn where not all of the cell area is the text area. If // we check only the text then the tooltip doesn't move when the user moves the mouse from one cell // to another cell that happens to contain the same text. if (overSameCell && m_toolTip.GetToolTip(this) == cellText) { return; } SetToolTip(cellText); }