DataGridViewCell.ToolTipText 屬性

定義

取得或設定與這個儲存格相關聯的工具提示文字。

public:
 property System::String ^ ToolTipText { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Browsable(false)]
public string ToolTipText { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.ToolTipText : string with get, set
Public Property ToolTipText As String

屬性值

與這個儲存格相關聯的工具提示文字。 預設為 Empty

屬性

範例

下列程式代碼範例示範如何在事件的事件處理程式CellFormatting內設定 ToolTipText 屬性。 此範例是 How to: Add ToolTips to Individual Cells in a Windows Forms DataGridView Control 中所提供的較大程式碼範例的一部分。

// Sets the ToolTip text for cells in the Rating column.
void dataGridView1_CellFormatting(Object^ /*sender*/, 
    DataGridViewCellFormattingEventArgs^ e)
{
    if ( (e->ColumnIndex == this->dataGridView1->Columns["Rating"]->Index)
        && e->Value != nullptr )
    {
        DataGridViewCell^ cell = 
            this->dataGridView1->Rows[e->RowIndex]->Cells[e->ColumnIndex];
        if (e->Value->Equals("*"))
        {                
            cell->ToolTipText = "very bad";
        }
        else if (e->Value->Equals("**"))
        {
            cell->ToolTipText = "bad";
        }
        else if (e->Value->Equals("***"))
        {
            cell->ToolTipText = "good";
        }
        else if (e->Value->Equals("****"))
        {
            cell->ToolTipText = "very good";
        }
    }
}
// Sets the ToolTip text for cells in the Rating column.
void dataGridView1_CellFormatting(object sender, 
    DataGridViewCellFormattingEventArgs e)
{
    if ( (e.ColumnIndex == this.dataGridView1.Columns["Rating"].Index)
        && e.Value != null )
    {
        DataGridViewCell cell = 
            this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
        if (e.Value.Equals("*"))
        {                
            cell.ToolTipText = "very bad";
        }
        else if (e.Value.Equals("**"))
        {
            cell.ToolTipText = "bad";
        }
        else if (e.Value.Equals("***"))
        {
            cell.ToolTipText = "good";
        }
        else if (e.Value.Equals("****"))
        {
            cell.ToolTipText = "very good";
        }
    }
}
' Sets the ToolTip text for cells in the Rating column.
Sub dataGridView1_CellFormatting(ByVal sender As Object, _
    ByVal e As DataGridViewCellFormattingEventArgs) _
    Handles dataGridView1.CellFormatting

    If e.ColumnIndex = Me.dataGridView1.Columns("Rating").Index _
        AndAlso (e.Value IsNot Nothing) Then

        With Me.dataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex)

            If e.Value.Equals("*") Then
                .ToolTipText = "very bad"
            ElseIf e.Value.Equals("**") Then
                .ToolTipText = "bad"
            ElseIf e.Value.Equals("***") Then
                .ToolTipText = "good"
            ElseIf e.Value.Equals("****") Then
                .ToolTipText = "very good"
            End If

        End With

    End If

End Sub

備註

當滑鼠指標位於儲存格上方,且屬性值不是 Empty時,這個屬性的值會顯示為數據格工具提示。 如果這個屬性的值是 Empty,如果儲存格顯示中的值被截斷,單元格就會顯示包含儲存格值的 ToolTip;否則,單元格將不會顯示 ToolTip。 您也可以將 屬性設定 DataGridView.ShowCellToolTipsfalse,以防止顯示工具提示。

DataGridView當控件DataSource屬性設定或其VirtualMode屬性為 true時,取得 屬性的值ToolTipText會引發 CellToolTipTextNeeded 控件的事件,並傳回 DataGridViewCellToolTipTextNeededEventArgs.ToolTipText 事件處理程式中指定的屬性值。 如果沒有事件的處理程式,取得 屬性的值 ToolTipText 會傳回先前指定的值或預設值 Empty

CellToolTipTextNeeded處理事件主要用於處理大量數據,以避免在設定多個單元格的數據格ToolTipText值時降低效能。 如需詳細資訊,請參閱 縮放 Windows Form DataGridView 控制項的最佳做法

如果存在,變更這個屬性會 CellToolTipTextChanged 引發擁有 DataGridView上的 事件。

適用於

另請參閱