New to Telerik UI for WinFormsStart a free 30-day trial

How to Show ToolTip for RadSpreadsheet Cell

Updated over 6 months ago

Environment

Product VersionProductAuthor
2023.2.606RadSpreadsheet for WinFormsDinko Krastev

Description

For performance reasons, the cells in RadSpreadsheet are not separate elements and this prevents us from using the ToolTipTextNeeded event like in other controls.

Solution

To add a tooltip to a cell, we will need to subscribe to the MouseMove event of the ActiveWorksheetEditor. In the event handler, we can create our own instance of a RadToolTip and call its Show() method. Here is how you can get the cell under the mouse and show the tooltip:

spreadsheet-cell-tooltip

C#
private RadWorksheetEditor editor = null;

public Form1()
{
	InitializeComponent();
	this.radSpreadsheet1.SpreadsheetElement.ActiveSheetEditorChanged += SpreadsheetElement_ActiveSheetEditorChanged;
}

private void SpreadsheetElement_ActiveSheetEditorChanged(object sender, EventArgs e)
{
	if (this.editor != null)
		this.editor.MouseMove -= Editor_MouseMove;

	this.editor = this.radSpreadsheet1.ActiveWorksheetEditor;

	if (this.editor != null)
		this.editor.MouseMove += Editor_MouseMove;
}

private RadToolTip toolTip = new RadToolTip();
private string lastCellName = "";

private void Editor_MouseMove(object sender, MouseEventArgs e)
{
	var activePresenter = this.radSpreadsheet1.ActiveWorksheetEditor.ActivePresenter as NormalWorksheetEditorPresenter;

	if (activePresenter != null)
	{
		Point point = activePresenter.PointFromControl(e.Location);
		CellIndex cellIndex = activePresenter.GetCellIndexFromViewPoint(point);
		string cellName = NameConverter.ConvertCellIndexToName(cellIndex);

		if (lastCellName != cellName)
		{
			toolTip.Show(cellName, Cursor.Position);
			lastCellName = cellName;
		}

		if (cellIndex != null && cellIndex.RowIndex == 0)
		{
			toolTip.Hide();
		}			
	}
}
    
In this article
EnvironmentDescriptionSolution
Not finding the help you need?
Contact Support