C# DataGridView工具脚本文本未显示

C# DataGridView工具脚本文本未显示,c#,visual-studio,visual-studio-2008,datagridview,desktop-application,C#,Visual Studio,Visual Studio 2008,Datagridview,Desktop Application,我在桌面应用程序中有数据绑定DataGridView,其中的列设置了ToolTipText属性,但当我将鼠标悬停在网格视图(单元格或单元格标题)上时,不会显示工具提示 网格视图的ShowCellToolTips属性是true,我已经使用断点验证了它在鼠标悬停之前没有以编程方式更改 我曾尝试创建一个CellToolTipTextRequired事件处理程序来查看工具提示文本是什么,但从未调用该事件处理程序 有什么我错过的吗 谢谢, 抢劫 编辑:我们使用的是Framework2.0。我不知道这个技巧

我在桌面应用程序中有数据绑定
DataGridView
,其中的列设置了
ToolTipText
属性,但当我将鼠标悬停在网格视图(单元格或单元格标题)上时,不会显示工具提示

网格视图的
ShowCellToolTips
属性是
true
,我已经使用断点验证了它在鼠标悬停之前没有以编程方式更改

我曾尝试创建一个
CellToolTipTextRequired
事件处理程序来查看工具提示文本是什么,但从未调用该事件处理程序

有什么我错过的吗

谢谢, 抢劫


编辑:我们使用的是Framework2.0。

我不知道这个技巧是否能解决您的特定问题,但您是否使用VS2008的SP1?
正如我所发现的,此Service Pack解决了许多不同的问题。

从您的问题中可以看出,您设置了列的工具提示文本。
列工具提示文本仅在浮动在标题上方时显示。要在单元格上显示工具提示文本,您必须连接
CellToolTipTextNeeded
事件,并在事件参数中设置
e.ToolTipText
的值,最后我们使用工具提示小部件和
CellMouseEnter
CellMouseLeave
事件来适当地显示它。不是最优的,但它可以解决我们遇到的奇怪行为。

尝试使用Cell.ToolTipText属性。您可能需要循环DataGridView的行并手动设置工具提示:

 For Each row As DataGridViewRow In Me.DataGridView.Rows
   Me.DataGridView("MyCol", row.Index).ToolTipText = "MyToolTipText"
 Next

可能不适合具有大量行的绑定DataGridView,但对于具有数百行的未绑定DataGridView,它可以成功地工作。希望这能有所帮助。

我目前在Framework 3.5上也遇到了同样的问题。似乎需要设置DataSource属性才能触发CelToolTipTextRequired事件。

当我向表单中添加一个带有单个(空)列的datagridview时,向该列的ToolTipText属性添加了文本,并确保datagridview的ShowCellToolTips属性设置为True,当我将鼠标悬停在该列的标题上时,确实会弹出一个工具提示。这似乎与原始问题中的陈述相矛盾,但在我的测试中,网格没有数据绑定。我不确定这是否有区别。但是,在具有数据绑定datagridview的项目上,我只使用了一个工具提示组件:

(1) 将工具提示组件添加到表单中
(2) 将datagridview的“工具提示1上的工具提示”(或工具提示组件的等效名称)属性设置为要显示的任何文本。
(3) 将datagridview的ShowCellToolTips属性设置为False。

(4) 中提琴!工作正常。

我发现这篇文章在寻找关于设置每行工具提示的帮助

我只是想确认在VS2008 SP1中处理CellToolTipText事件对我是有效的

对于那些想知道如何将文本设置为基础数据行中的值的人,这可能很有用:

    private void myDGV_CellToolTipTextNeeded(object sender, DataGridViewCellToolTipTextNeededEventArgs e)
    {
        // This is used to set tooltiptext for individual cells in the grid.
        if (e.ColumnIndex == 2)  // I only want tooltips for the second column (0-based)
        {
            if (e.RowIndex >= 0)   // When grid is initialized rowindex == 0
            {
                // e.ToolTipText = "this is a test."; // static example.

                DataRowView drv = ((DataGridView)sender).Rows[e.RowIndex].DataBoundItem as DataRowView;
                MyTableRowClass theRow = drv.Row as MyTableRowClass;
                e.ToolTipText = theRow.Col1  + "\r\n" + theRow.Col2;
            }
        }
    }

我有一个simular问题,但通过在我的DataGridView上将ShowCellToolTip设置为true,我能够纠正它。一旦我做到了这一点,我就能够发送以下代码,一切都很好

tableDocTypes.ShowCellToolTips = true;
tableDocTypes.Rows[i].Cells[columnFormCabinet.Index].ToolTipText = "Cabinet is not defined on the optical server.";
  • 将DataGridView的
    ShowCellToolTips
    属性设置为
    false
  • 将此代码放入DataGridView的
    CellMouseEnter
    事件中

    private void dgv_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
    {
        if (!(dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].GetType() == typeof(DataGridViewImageCell))) return;
        System.Windows.Forms.ToolTip tlp = new System.Windows.Forms.ToolTip();
        tlp.SetToolTip(dgv, "Your ToolTipText");
    }
    

  • 要显示网格单元格的工具提示,可以使用此事件处理程序“CellToolTipTextRequired”。请参阅下面的代码片段

    this.dataGridView1.ShowCellToolTips = true;
    this.dataGridView1.CellToolTipTextNeeded += dataGridView1_CellToolTipTextNeeded;
    
    void dataGridView1_CellToolTipTextNeeded(object sender, DataGridViewCellToolTipTextNeededEventArgs e)
    {
        if (e.ColumnIndex >= 0 && e.RowIndex >= 0)           
        {
            e.ToolTipText = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
        }
    }
    

    将datagridview ShowCellToolTips属性设置为False时,CellToolTiptExtRequired只会偶尔被调用,这与此相关。当单元格溢出时,该行为是工具提示上的工具提示。 当单元格的WrapMode设置为true时,每次都会正确调用CellToolTipTextNeeded。 我认为CellToolTiptextRequired将被调用并覆盖通用工具提示,但它似乎只在datagridview.cell的第一个条目上调用此事件,然后,如果鼠标离开单元格并重新打开(保留在datagridview中),则会显示“视图溢出工具提示”


    无论如何,这些信息可能会帮助其他人。

    @WunderWuzzi。不,我们没有安装SP1。我会和项目的技术负责人谈谈,看看我们是否可以尝试一下。那我就更新这个问题。非常感谢。感谢您的回复,但正如问题中所述:a)工具提示文本也没有显示在标题上b)CellToolTipTextNeeded事件处理程序没有运行它对我有效:private void dgvPlatypus_CellToolTipTextNeedEventArgs(对象发送方,DataGridViewCellToolTipTextNeedEventArgs e){e.ToolTipText=“j.cutworm是朋克”}CellToolTipTextNeeded未被解雇。有什么提示吗?在我的情况下,它也没有被解雇,但我写了它,它工作得很好
    this.dataGridView1.cellToolTiptextRequired+=dataGridView1\u cellToolTiptextRequired
    private void dataGridView1\u CellToolTipTextNeededEventArgs(对象发送者,DataGridViewCellToolTipTextNeedEventArgs e){e.ToolTipText=“Trying”;}
    我知道这是一个老问题,但破解工具提示组件真的是正确答案吗?列/单元格工具提示未显示时,我们遇到了相同的问题。这似乎是DataGridView中的一个bug,应该得到修复。@yoopegeek我同意,这是一个bug。我听说它在Framework 3.0中已修复,但由于安装程序的限制,我们无法升级。我使用的是3.5…仍然没有修复。;)@sindre在我的例子中,数据源是明确设置的,否则我的GridView中就没有数据了。这可能是测试正确列的更好方法。如果您重新排列列的顺序,它仍然有效。如果(myDGV.Columns[e.ColumnIndex].Name==“MyColumn”),这是正确答案。来自MSDN:“CellToolTiptextRequired事件仅在