DataGridViewCellToolTipTextNeededEventArgs Class
Provides data for the CellToolTipTextNeeded event.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
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.
Public Sub dataGridView1_CellToolTipTextNeeded(ByVal sender As Object, _ ByVal e As DataGridViewCellToolTipTextNeededEventArgs) _ Handles dataGridView1.CellToolTipTextNeeded Dim newLine As String = Environment.NewLine If e.RowIndex > -1 Then Dim dataGridViewRow1 As DataGridViewRow = _ dataGridView1.Rows(e.RowIndex) ' Add the employee's ID to the ToolTipText. e.ToolTipText = String.Format("EmployeeID {0}: {1}", _ dataGridViewRow1.Cells("EmployeeID").Value.ToString(), _ newLine) ' Add the employee's name to the ToolTipText. e.ToolTipText += String.Format("{0} {1} {2} {3}", _ dataGridViewRow1.Cells("TitleOfCourtesy").Value.ToString(), _ dataGridViewRow1.Cells("FirstName").Value.ToString(), _ dataGridViewRow1.Cells("LastName").Value.ToString(), _ newLine) ' Add the employee's title to the ToolTipText. e.ToolTipText += String.Format("{0}{1}{2}", _ dataGridViewRow1.Cells("Title").Value.ToString(), _ newLine, newLine) ' Add the employee's contact information to the ToolTipText. e.ToolTipText += String.Format("{0}{1}{2}, ", _ dataGridViewRow1.Cells("Address").Value.ToString(), newLine, _ dataGridViewRow1.Cells("City").Value.ToString()) If Not String.IsNullOrEmpty( _ dataGridViewRow1.Cells("Region").Value.ToString()) e.ToolTipText += String.Format("{0}, ", _ dataGridViewRow1.Cells("Region").Value.ToString()) End If e.ToolTipText += String.Format("{0}, {1}{2}{3} EXT:{4}{5}{6}", _ dataGridViewRow1.Cells("Country").Value.ToString(), _ dataGridViewRow1.Cells("PostalCode").Value.ToString(), _ newLine, _ dataGridViewRow1.Cells("HomePhone").Value.ToString(), _ dataGridViewRow1.Cells("Extension").Value.ToString(), _ newLine, newLine) ' Add employee information to the ToolTipText. Dim HireDate As DateTime = _ CType(dataGridViewRow1.Cells("HireDate").Value, DateTime) e.ToolTipText += _ String.Format("Employee since: {0}/{1}/{2}{3}Manager: {4}", _ HireDate.Month.ToString(), HireDate.Day.ToString(), _ HireDate.Year.ToString(), newLine, _ dataGridViewRow1.Cells("Manager").Value.ToString()) End If End Sub
System.EventArgs
System.Windows.Forms.DataGridViewCellEventArgs
System.Windows.Forms.DataGridViewCellToolTipTextNeededEventArgs
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.