DataGridViewCellToolTipTextNeededEventHandler DataGridViewCellToolTipTextNeededEventHandler DataGridViewCellToolTipTextNeededEventHandler DataGridViewCellToolTipTextNeededEventHandler Delegate

정의

CellToolTipTextNeededDataGridView 이벤트를 처리할 메서드를 나타냅니다.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)

매개 변수

sender
Object Object Object Object

이벤트 소스입니다.The source of the event.

상속
DataGridViewCellToolTipTextNeededEventHandlerDataGridViewCellToolTipTextNeededEventHandlerDataGridViewCellToolTipTextNeededEventHandlerDataGridViewCellToolTipTextNeededEventHandler

예제

다음 코드 예제에서 셀 내용에 대 한 추가 정보를 표시할 도구 설명을 사용 하 여 ReportsTo 열입니다.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

설명

CellToolTipTextNeeded 이벤트에만 발생 경우를 DataGridView 컨트롤 DataSource 속성을 설정 또는 해당 VirtualMode 속성은 true합니다.The CellToolTipTextNeeded event occurs only when the DataGridView control DataSource property is set or its VirtualMode property is true.

처리 하는 경우는 CellToolTipTextNeeded 이벤트 처리기에 지정한 도구 설명 텍스트가 표시 됩니다 때마다 마우스 포인터가 위에 있는 컨트롤 및 셀 ShowCellToolTips 속성 값이 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. CellToolTipTextNeeded 이벤트는 현재 상태 또는 셀의 값에 의해 결정 되는 도구 설명을 표시 하려는 경우에 유용 합니다.The CellToolTipTextNeeded event is useful when you want to display ToolTips determined by the current state or value of a cell.

CellToolTipTextNeeded 이벤트는 또한 될 때마다 발생의 값을 DataGridViewCell.ToolTipText 검색 하거나 프로그래밍 방식으로 또는 마우스 포인터가 셀에 들어갈 때.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.

사용할 수는 DataGridViewCellEventArgs.ColumnIndexRowIndex 속성은 셀의 값을 상태를 확인 하 고이 정보를 사용 하 여 설정 하는 ToolTipText 속성입니다.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. 이 속성은 셀의 값을 사용 하 여 초기화 ToolTipText 이벤트 값을 재정의 하는 속성입니다.This property is initialized with the value of the cell ToolTipText property, which the event value overrides.

처리를 CellToolTipTextNeeded 많은 양의 데이터로 작업할 때 이벤트 ToolTipText 여러 셀에 대 한 값입니다.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. 자세한 내용은 Windows Forms DataGridView 컨트롤의 크기 조정에 대 한 모범 사례합니다.For more information, see Best Practices for Scaling the Windows Forms DataGridView Control.

이벤트를 처리 하는 방법에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.For more information about how to handle events, see Handling and Raising Events.

DataGridViewCellToolTipTextNeededEventHandler 대리자를 만들 때, 이벤트를 처리할 메서드를 식별합니다.When you create a DataGridViewCellToolTipTextNeededEventHandler delegate, you identify the method that will handle the event. 이벤트를 이벤트 처리기와 연결하려면 대리자의 인스턴스를 해당 이벤트에 추가합니다.To associate the event with your event handler, add an instance of the delegate to the event. 대리자를 제거하지 않는 경우 이벤트가 발생할 때마다 이벤트 처리기가 호출됩니다.The event handler is called whenever the event occurs, unless you remove the delegate. 이벤트 처리기 대리자에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.For more information about event-handler delegates, see Handling and Raising Events.

확장 메서드

GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate)

지정된 대리자가 나타내는 메서드를 나타내는 개체를 가져옵니다.Gets an object that represents the method represented by the specified delegate.

적용 대상

추가 정보