8

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

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

我试图创建一个CellToolTipTextNeeded事件处理程序,看看有什么工具提示文本为,但该事件处理程序不会被调用。

有什么我错过了吗?

感谢, 罗布

编辑:我们使用框架2.0。

+0

我知道这是一个老问题,但黑客工作,与周围的工具提示组件真正正确的答案?我们遇到与列/单元格工具提示未显示相同的问题。这看起来像DataGridView中的一个应该得到解决的错误。 – Yoopergeek 2010-01-27 14:31:13

+0

@Yoopergeek我同意,这是一个错误。我被告知它已在Framework 3.0中修复,但由于安装程序的限制,我们无法升级。 – 2010-01-27 14:41:29

+1

我使用3.5 ...还没有修复。 ;) – Yoopergeek 2010-01-27 14:55:56

回答

2

我们结束了使用工具提示窗口小部件和CellMouseEnter设置e.ToolTipText值的细胞提示文本,CellMouseLeave事件以适当表现出来。不是最佳的,但它适用于我们遇到的奇怪行为。

0

我不知道这个提示是否是针对您的特定问题的解决方案,但是您是否使用VS2008的SP1? 正如我发现的,此Service Pack解决了许多不同的问题。

+0

@WunderWuzzi。不,我们没有安装SP1。我会和项目的技术负责人交谈,看看我们能不能尝试。 然后我会更新问题。非常感谢。 – 2009-01-02 14:19:12

8

从您的问题看来,您设置了列的工具提示文本。 仅当悬浮在标题上时,才会显示列提示文本。为了表示对你有来装CellToolTipTextNeeded事件和事件参数

+0

感谢您的答复,但作为问题指出: 一)提示文本没有显示在CellToolTipTextNeeded事件处理函数不是射击 – 2009-01-08 19:27:49

+0

头要么 B)这对我的作品中:private void dgvPlatypus_CellToolTipTextNeeded(对象发件人,DataGridViewCellToolTipTextNeededEventArgs e){e.ToolTipText =“j。cutworm是一个朋克”; } – 2012-09-14 22:52:33

+0

CellToolTipTextNeeded没有被激发。任何提示呢? – Kenta 2013-10-24 11:54:42

4

尝试使用Cell.ToolTipText属性。你可能会需要循环DataGridView中的行和手动设置提示:

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

可能不适合用于大量的行绑定的DataGridView,但与未绑定的DataGridView有几百成功对我的作品行。希望这可以帮助。

1

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

3

当我添加一个带有单个(空)列的datagridview到表单时,将文本添加到该列的ToolTipText属性,并确保将datagridview的ShowCellToolTips属性设置为True,我得到一个工具提示弹出当我将鼠标悬停在该列的标题上时。这似乎与原始问题中陈述的内容相矛盾,但在我的测试中,网格并未受到数据的限制。不知道这是否有所作为。然而,与数据绑定datagridview的一个项目,我只是用一个工具提示组件:

(1)工具提示组件添加到您的窗体。
(2)将您的datagridview的ToolTip on toolTip1(或您的ToolTip组件的等效名称)属性设置为要显示的任何文本。
(3)将你的datagridview的ShowCellToolTips属性设置为False。
(4)Viola!按预期工作。

0

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

我只想确认在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; 
      } 
     } 
    } 
1

我有一个simular问题,但能够通过设置来纠正它ShowCellToolTip在我的DataGridView上为true。一旦我这样做,我能够发送以下代码,一切正常。

tableDocTypes.ShowCellToolTips = true; 
tableDocTypes.Rows[i].Cells[columnFormCabinet.Index].ToolTipText = "Cabinet is not defined on the optical server."; 
0
  1. 设置你的DataGridView的ShowCellToolTips属性false
  2. 将这个代码在你的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"); 
    } 
    
2

要显示网格单元的提示,你可以使用此事件处理程序“CellToolTipTextNeeded“。请参考下面的代码片段,

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(); 
    } 
} 
1

设置的datagridview ShowCellToolTips属性设为False