DataGridView.CellToolTipTextNeeded 이벤트

정의

셀의 도구 설명 텍스트가 필요할 때 발생합니다.

public:
 event System::Windows::Forms::DataGridViewCellToolTipTextNeededEventHandler ^ CellToolTipTextNeeded;
public event System.Windows.Forms.DataGridViewCellToolTipTextNeededEventHandler CellToolTipTextNeeded;
public event System.Windows.Forms.DataGridViewCellToolTipTextNeededEventHandler? CellToolTipTextNeeded;
member this.CellToolTipTextNeeded : System.Windows.Forms.DataGridViewCellToolTipTextNeededEventHandler 
Public Custom Event CellToolTipTextNeeded As DataGridViewCellToolTipTextNeededEventHandler 

이벤트 유형

예제

다음 코드 예제에서는 데이터 바인딩된 DataGridView 컨트롤에 숨겨진 열의 정보를 표시 하는 이벤트 처리기를 사용 CellToolTipTextNeeded 하는 방법을 보여 줍니다.

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

설명

CellToolTipTextNeeded 이벤트에만 발생 경우를 DataGridView 컨트롤 DataSource 속성을 설정 또는 해당 VirtualMode 속성은 true합니다.

이벤트를 처리 CellToolTipTextNeeded 할 때 처리기에서 지정한 도구 설명 텍스트는 속성 값이 이고 마우스 포인터가 true 셀 위에 있거나 사용자가 키보드를 사용하여 셀로 이동하는 경우 ShowCellToolTips 표시됩니다. 이 CellToolTipTextNeeded 이벤트는 셀의 현재 상태 또는 값에 따라 결정되는 ToolTips를 표시하려는 경우에 유용합니다.

이벤트는 CellToolTipTextNeeded 속성의 DataGridViewCell.ToolTipText 값을 검색할 때마다 프로그래밍 방식으로 또는 사용자가 마우스 또는 키보드를 사용하여 셀로 이동할 때도 발생합니다.

RowIndex 속성을 사용하여 DataGridViewCellEventArgs.ColumnIndex 셀의 상태 또는 값을 확인하고 이 정보를 사용하여 속성을 변경하거나 수정할 DataGridViewCellToolTipTextNeededEventArgs.ToolTipText 수 있습니다. 이 속성은 이벤트 값이 재정의하는 셀 ToolTipText 속성 값으로 초기화됩니다.

여러 셀의 CellToolTipTextNeededToolTipText 값을 설정하는 성능 저하를 방지하기 위해 대량의 데이터로 작업할 때 이벤트를 처리합니다. 자세한 내용은 Windows Forms DataGridView 컨트롤의 크기를 조정하는 최선의 방법을 참조하세요.

이벤트를 처리 하는 방법에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.

적용 대상

추가 정보