DataGridViewCellToolTipTextNeededEventHandler Delegado

Definición

Representa el método que controlará el evento CellToolTipTextNeeded de DataGridView.Represents the method that will handle the CellToolTipTextNeeded event of a DataGridView.

public delegate void DataGridViewCellToolTipTextNeededEventHandler(System::Object ^ sender, DataGridViewCellToolTipTextNeededEventArgs ^ e);
public delegate void DataGridViewCellToolTipTextNeededEventHandler(object sender, DataGridViewCellToolTipTextNeededEventArgs e);
type DataGridViewCellToolTipTextNeededEventHandler = delegate of obj * DataGridViewCellToolTipTextNeededEventArgs -> unit
Public Delegate Sub DataGridViewCellToolTipTextNeededEventHandler(sender As Object, e As DataGridViewCellToolTipTextNeededEventArgs)

Parámetros

sender
Object

Origen del evento.The source of the event.

Herencia
DataGridViewCellToolTipTextNeededEventHandler

Ejemplos

En el ejemplo de código siguiente se usa la información sobre herramientas para mostrar información adicional ReportsTo sobre el contenido de la celda en la columna.The following code example uses ToolTips to display additional information about cell contents in the ReportsTo column.

DataTable^ Populate( String^ query, bool resetUnsharedCounter )
{
    if ( resetUnsharedCounter )
    {
        ResetCounter();
    }


    // Alter the data source as necessary
    SqlDataAdapter^ adapter = gcnew SqlDataAdapter( query,
        gcnew SqlConnection( L"Integrated Security=SSPI;Persist Security Info=False;"
        L"Initial Catalog=Northwind;Data Source= localhost" ) );
    DataTable^ table = gcnew DataTable;
    adapter->Fill( table );
    return table;
}

Label^ count;
int unsharedRowCounter;
void ResetCounter()
{
    unsharedRowCounter = 0;
    count->Text = unsharedRowCounter.ToString();
}

void dataGridView1_CellToolTipTextNeeded( Object^ /*sender*/,
    DataGridViewCellToolTipTextNeededEventArgs^ e )
{
    if ( theCellImHoveringOver->ColumnIndex == dataGridView1->Columns[ L"ReportsTo" ]->Index && theCellImHoveringOver->RowIndex > -1 )
    {
        String^ reportsTo = dataGridView1->Rows[ theCellImHoveringOver->RowIndex ]->Cells[ theCellImHoveringOver->ColumnIndex ]->Value->ToString();
        if ( reportsTo->Equals( L"" ) )
        {
            e->ToolTipText = L"The buck stops here!";
        }
        else
        {
            DataTable^ table = Populate( String::Format( L"select firstname, lastname from employees where employeeid = '{0}'",
                dataGridView1->Rows[ theCellImHoveringOver->RowIndex ]->Cells[ theCellImHoveringOver->ColumnIndex ]->Value ), false );
            e->ToolTipText = String::Format( L"Reports to {0} {1}", table->Rows[ 0 ]->ItemArray[ 0 ], table->Rows[ 0 ]->ItemArray[ 1 ] );
        }
    }
}


private DataTable Populate(string query, bool resetUnsharedCounter)
{
    if (resetUnsharedCounter)
    {
        ResetCounter();
    }

    // Alter the data source as necessary
    SqlDataAdapter adapter = new SqlDataAdapter(query,
        new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;" +
        "Initial Catalog=Northwind;Data Source=localhost"));

    DataTable table = new DataTable();
    table.Locale = System.Globalization.CultureInfo.InvariantCulture;
    adapter.Fill(table);
    return table;
}

private Label count = new Label();
private int unsharedRowCounter;

private void ResetCounter()
{
    unsharedRowCounter = 0;
    count.Text = unsharedRowCounter.ToString();
}

private void dataGridView1_CellToolTipTextNeeded(object sender,
    DataGridViewCellToolTipTextNeededEventArgs e)
{

    if (theCellImHoveringOver.ColumnIndex == dataGridView1.Columns["ReportsTo"].Index &&
        theCellImHoveringOver.RowIndex > -1)
    {

        string reportsTo = dataGridView1.Rows[theCellImHoveringOver.RowIndex].
            Cells[theCellImHoveringOver.ColumnIndex].Value.ToString();

        if (String.IsNullOrEmpty(reportsTo))
        {
            e.ToolTipText = "The buck stops here!";
        }
        else
        {
            DataTable table = Populate(
                "select firstname, lastname from employees where employeeid = '" +
                dataGridView1.Rows[theCellImHoveringOver.RowIndex].
                Cells[theCellImHoveringOver.ColumnIndex].Value.ToString() +
                "'", false);

            e.ToolTipText = "Reports to " + table.Rows[0].ItemArray[0] + " " +
                table.Rows[0].ItemArray[1];
        }
    }
}
Private Function Populate(ByVal query As String, ByVal resetUnsharedCounter As Boolean) As DataTable

    If resetUnsharedCounter Then
        ResetCounter()
    End If

    ' Alter the data source as necessary
    Dim adapter As New SqlDataAdapter(query, _
        New SqlConnection("Integrated Security=SSPI;Persist Security Info=False;" & _
        "Initial Catalog=Northwind;Data Source=localhost"))

    Dim table As New DataTable()
    table.Locale = System.Globalization.CultureInfo.InvariantCulture
    adapter.Fill(table)
    Return table
End Function

Private count As New Label()
Private unsharedRowCounter As Integer

Private Sub ResetCounter()
    unsharedRowCounter = 0
    count.Text = unsharedRowCounter.ToString()
End Sub

Private Sub DataGridView1_CellToolTipTextNeeded(ByVal sender As Object, _
    ByVal e As DataGridViewCellToolTipTextNeededEventArgs) _
    Handles dataGridView1.CellToolTipTextNeeded

    If theCellImHoveringOver.ColumnIndex = dataGridView1.Columns("ReportsTo").Index AndAlso _
            theCellImHoveringOver.RowIndex > -1 Then

        Dim reportsTo As String = dataGridView1.Rows(theCellImHoveringOver.RowIndex). _
            Cells(theCellImHoveringOver.ColumnIndex).Value.ToString()
        If String.IsNullOrEmpty(reportsTo) Then
            e.ToolTipText = "The buck stops here!"
        Else
            Dim table As DataTable = Populate( _
                "select firstname, lastname from employees where employeeid = '" & _
                dataGridView1.Rows(theCellImHoveringOver.RowIndex). _
                Cells(theCellImHoveringOver.ColumnIndex).Value.ToString() & _
                "'", False)

            e.ToolTipText = "Reports to " & table.Rows(0).Item(0).ToString() & " " & table.Rows(0).Item(1).ToString()
        End If
    End If
End Sub

Comentarios

El CellToolTipTextNeeded evento solo se produce cuando DataGridView se DataSource establece la propiedad del control VirtualMode o su truepropiedad es.The CellToolTipTextNeeded event occurs only when the DataGridView control DataSource property is set or its VirtualMode property is true.

Al controlar el CellToolTipTextNeeded evento, se muestra el texto de información sobre herramientas que se especifica en el controlador cuando el puntero del mouse se encuentra sobre una celda y trueel valor de la propiedad del control ShowCellToolTips es.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. El CellToolTipTextNeeded evento es útil cuando se desea mostrar información sobre herramientas determinada por el estado o el valor actual de una celda.The CellToolTipTextNeeded event is useful when you want to display ToolTips determined by the current state or value of a cell.

El CellToolTipTextNeeded evento también se produce siempre que se recupera DataGridViewCell.ToolTipText el valor de la propiedad, ya sea mediante programación o cuando el puntero del Mouse entra en una celda.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.

Puede utilizar las DataGridViewCellEventArgs.ColumnIndex propiedades y RowIndex para determinar el estado o el valor de una celda y utilizar esta información para establecer la ToolTipText propiedad.You can use the DataGridViewCellEventArgs.ColumnIndex and RowIndex properties to determine the state or value of a cell, and use this information to set the ToolTipText property. Esta propiedad se inicializa con el valor de la propiedad de ToolTipText celda, que reemplaza el valor de evento.This property is initialized with the value of the cell ToolTipText property, which the event value overrides.

Controle CellToolTipTextNeeded el evento al trabajar con grandes cantidades de datos para evitar las penalizaciones en el rendimiento de ToolTipText establecer el valor de la celda para varias celdas.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. Para obtener más información, consulte Procedimientos recomendados para ajustar la escala del control DataGridView en Windows Forms.For more information, see Best Practices for Scaling the Windows Forms DataGridView Control.

Para obtener más información acerca de cómo controlar eventos, vea controlar y provocar eventos.For more information about how to handle events, see Handling and Raising Events.

Cuando se crea un delegado DataGridViewCellToolTipTextNeededEventHandler, se identifica el método que controlará el evento.When you create a DataGridViewCellToolTipTextNeededEventHandler delegate, you identify the method that will handle the event. Para asociar el evento al controlador, se debe agregar una instancia del delegado al evento.To associate the event with your event handler, add an instance of the delegate to the event. Siempre que se produce el evento, se llama a su controlador, a menos que se quite el delegado.The event handler is called whenever the event occurs, unless you remove the delegate. Para obtener más información sobre los delegados de controladores de eventos, vea controlar y provocar eventos.For more information about event-handler delegates, see Handling and Raising Events.

Métodos de extensión

GetMethodInfo(Delegate)

Obtiene un objeto que representa el método representado por el delegado especificado.Gets an object that represents the method represented by the specified delegate.

Se aplica a

Consulte también: