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只有在設定控件DataSource屬性或其屬性為 trueDataGridView,才會VirtualMode發生此事件。

當您處理 CellToolTipTextNeeded 事件時,每當滑鼠指標位於儲存格上方,且控件 ShowCellToolTips 屬性值為 true時,就會顯示處理程式中指定的工具提示文字。 當您想要顯示數據格目前狀態或值所決定的工具提示時,此 CellToolTipTextNeeded 事件很有用。

CellToolTipTextNeeded每當以程式設計方式擷取屬性的值DataGridViewCell.ToolTipText,或滑鼠指標進入單元格時,也會發生此事件。

您可以使用 ColumnIndexRowIndex 屬性來判斷儲存格的狀態或值,並使用這項資訊來設定 ToolTipText 屬性。 這個屬性會使用事件值覆寫的儲存格 ToolTipText 屬性值初始化。

CellToolTipTextNeeded處理大量數據時處理事件,以避免設定ToolTipText多個儲存格單元格值的效能負面影響。 如需詳細資訊,請參閱 縮放 Windows Form DataGridView 控制項的最佳做法

如需如何處理事件的詳細資訊,請參閱 處理和引發事件

屬性

ColumnIndex

取得值,指出發生事件之儲存格的資料行索引。

(繼承來源 DataGridViewCellEventArgs)
RowIndex

取得值,指出發生事件之儲存格的資料列索引。

(繼承來源 DataGridViewCellEventArgs)
ToolTipText

取得或設定工具提示文字。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱