This documentation is archived and is not being maintained.

DataGridViewCellToolTipTextNeededEventArgs Class

Provides data for the CellToolTipTextNeeded event.


Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public class DataGridViewCellToolTipTextNeededEventArgs : DataGridViewCellEventArgs

The DataGridViewCellToolTipTextNeededEventArgs type exposes the following members.

Public propertyColumnIndexGets a value indicating the column index of the cell that the event occurs for. (Inherited from DataGridViewCellEventArgs.)
Public propertyRowIndexGets a value indicating the row index of the cell that the event occurs for. (Inherited from DataGridViewCellEventArgs.)
Public propertyToolTipTextGets or sets the ToolTip text.

Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

The CellToolTipTextNeeded event occurs only when the DataGridView control DataSource property is set or its VirtualMode property is true.

When you handle the CellToolTipTextNeeded event, the ToolTip text you specify in the handler is shown whenever the mouse pointer is over a cell and the control ShowCellToolTips property value is true. The CellToolTipTextNeeded event is useful when you want to display ToolTips determined by the current state or value of a cell.

The CellToolTipTextNeeded event also occurs whenever the value of the DataGridViewCell.ToolTipText property is retrieved, either programmatically or when the mouse pointer enters a cell.

You can use the ColumnIndex and RowIndex properties to determine the state or value of a cell, and use this information to set the ToolTipText property. This property is initialized with the value of the cell ToolTipText property, which the event value overrides.

Handle the CellToolTipTextNeeded event when working with large amounts of data to avoid the performance penalties of setting the cell ToolTipText value for multiple cells. For more information, see Best Practices for Scaling the Windows Forms DataGridView Control.

For more information about handling events, see Consuming Events.

The following code example fills the ToolTipText with information from hidden cells in the DataGridView.

void dataGridView1_CellToolTipTextNeeded(object sender,
    DataGridViewCellToolTipTextNeededEventArgs e)
    string newLine = Environment.NewLine;
    if (e.RowIndex > -1)
        DataGridViewRow dataGridViewRow1 = dataGridView1.Rows[e.RowIndex];

        // Add the employee's ID to the ToolTipText.
        e.ToolTipText = String.Format("EmployeeID {0}:{1}",
            dataGridViewRow1.Cells["EmployeeID"].Value, newLine);

        // Add the employee's name to the ToolTipText.
        e.ToolTipText += String.Format("{0} {1} {2}{3}",

        // Add the employee's title to the ToolTipText.
        e.ToolTipText += String.Format("{0}{1}{2}",
            newLine, newLine);

        // Add the employee's contact information to the ToolTipText.
        e.ToolTipText += String.Format("{0}{1}{2}, ",
            dataGridViewRow1.Cells["Address"].Value.ToString(), newLine,
        if (!String.IsNullOrEmpty(
            e.ToolTipText += String.Format("{0}, ",
        e.ToolTipText += String.Format("{0}, {1}{2}{3} EXT:{4}{5}{6}",
            newLine, dataGridViewRow1.Cells["HomePhone"].Value.ToString(),
            newLine, newLine);

        // Add employee information to the ToolTipText.
        DateTime HireDate =
        e.ToolTipText +=
            String.Format("Employee since: {0}/{1}/{2}{3}Manager: {4}",
            HireDate.Month.ToString(), HireDate.Day.ToString(),
            HireDate.Year.ToString(), newLine,

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.