DataGridViewCellToolTipTextNeededEventArgs Clase

Definición

Proporciona datos para el evento CellToolTipTextNeeded.

public ref class DataGridViewCellToolTipTextNeededEventArgs : System::Windows::Forms::DataGridViewCellEventArgs
public class DataGridViewCellToolTipTextNeededEventArgs : System.Windows.Forms.DataGridViewCellEventArgs
type DataGridViewCellToolTipTextNeededEventArgs = class
    inherit DataGridViewCellEventArgs
Public Class DataGridViewCellToolTipTextNeededEventArgs
Inherits DataGridViewCellEventArgs
Herencia
DataGridViewCellToolTipTextNeededEventArgs

Ejemplos

En el ejemplo de código siguiente se rellena la ToolTipText información de las celdas ocultas de 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}",
            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 (!String.IsNullOrEmpty(
            dataGridViewRow1.Cells["Region"].Value.ToString()))
        {
            e.ToolTipText += String.Format("{0}, ",
                dataGridViewRow1.Cells["Region"].Value.ToString());
        }
        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.
        DateTime HireDate =
            (DateTime)dataGridViewRow1.Cells["HireDate"].Value;
        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());
    }
}
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

Comentarios

El CellToolTipTextNeeded evento solo se produce cuando se establece la propiedad de DataGridView control DataSource o su VirtualMode propiedad es true.

Al controlar el CellToolTipTextNeeded evento, el texto de información sobre herramientas que especifique en el controlador se muestra cada vez que el puntero del mouse se encuentra sobre una celda y el valor de la propiedad de control ShowCellToolTips es true. El CellToolTipTextNeeded evento es útil cuando desea mostrar información sobre herramientas determinada por el estado actual o el valor de una celda.

El CellToolTipTextNeeded evento también se produce cada vez que se recupera el valor de la DataGridViewCell.ToolTipText propiedad, ya sea mediante programación o cuando el puntero del mouse entra en una celda.

Puede usar las ColumnIndex propiedades y RowIndex para determinar el estado o el valor de una celda y usar esta información para establecer la ToolTipText propiedad . Esta propiedad se inicializa con el valor de la propiedad cell ToolTipText , que el valor del evento invalida.

Controle el CellToolTipTextNeeded evento al trabajar con grandes cantidades de datos para evitar las penalizaciones de rendimiento de establecer el valor de celda ToolTipText para varias celdas. Para obtener más información, consulte Procedimientos recomendados para ajustar la escala del control DataGridView en Windows Forms.

Para obtener más información acerca de cómo controlar eventos, vea controlar y provocar eventos.

Propiedades

ColumnIndex

Obtiene un valor que indica el índice de columna de la celda para la que se produce el evento.

(Heredado de DataGridViewCellEventArgs)
RowIndex

Obtiene un valor que indica el índice de fila de la celda para la que se produce el evento.

(Heredado de DataGridViewCellEventArgs)
ToolTipText

Obtiene o establece el texto de información sobre herramientas.

Métodos

Equals(Object)

Determina si el objeto especificado es igual que el objeto actual.

(Heredado de Object)
GetHashCode()

Sirve como la función hash predeterminada.

(Heredado de Object)
GetType()

Obtiene el Type de la instancia actual.

(Heredado de Object)
MemberwiseClone()

Crea una copia superficial del Object actual.

(Heredado de Object)
ToString()

Devuelve una cadena que representa el objeto actual.

(Heredado de Object)

Se aplica a

Consulte también