DataGridViewCellToolTipTextNeededEventArgs Класс

Определение

Предоставляет данные о событии 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
Наследование
DataGridViewCellToolTipTextNeededEventArgs

Примеры

В следующем примере кода заполняется данными ToolTipText из скрытых ячеек в 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

Комментарии

Событие CellToolTipTextNeeded возникает только в том случае, DataGridView если задано свойство элемента управления DataSource или его VirtualMode свойство равно true.

При обработке CellToolTipTextNeeded события текст подсказки, указанный в обработчике, отображается всякий раз, когда указатель мыши находится на ячейке, а значение свойства элемента управления ShowCellToolTips равно true. Событие CellToolTipTextNeeded полезно, если требуется отобразить подсказки, определяемые текущим состоянием или значением ячейки.

Это CellToolTipTextNeeded событие также возникает при каждом извлечении DataGridViewCell.ToolTipText значения свойства программным способом или при входе указателя мыши в ячейку.

Свойства и RowIndex можно использовать ColumnIndex для определения состояния или значения ячейки, а также использовать эти сведения для задания ToolTipText свойства . Это свойство инициализируется значением свойства ячейки ToolTipText , которое переопределяется значением события.

CellToolTipTextNeeded Обработайте событие при работе с большими объемами данных, чтобы избежать снижения производительности при установке значения ячейки ToolTipText для нескольких ячеек. Подробнее см. в разделе Масштабирование элемента управления DataGridView в Windows Forms.

Дополнительные сведения об обработке событий см. в разделе Обработка и вызов событий.

Свойства

ColumnIndex

Получает значение, показывающее индекс столбца ячейки, для которой произошло событие.

(Унаследовано от DataGridViewCellEventArgs)
RowIndex

Получает значение, показывающее индекс строки ячейки, для которой произошло событие.

(Унаследовано от DataGridViewCellEventArgs)
ToolTipText

Получает или задает текст подсказки.

Методы

Equals(Object)

Определяет, равен ли указанный объект текущему объекту.

(Унаследовано от Object)
GetHashCode()

Служит хэш-функцией по умолчанию.

(Унаследовано от Object)
GetType()

Возвращает объект Type для текущего экземпляра.

(Унаследовано от Object)
MemberwiseClone()

Создает неполную копию текущего объекта Object.

(Унаследовано от Object)
ToString()

Возвращает строку, представляющую текущий объект.

(Унаследовано от Object)

Применяется к

См. также раздел