在vb.net中的窗口应用程序的datagrid单元中显示工具提示 [英] show tooltip in datagrid cell for window application in vb.net

查看:89
本文介绍了在vb.net中的窗口应用程序的datagrid单元中显示工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在vb.net的datagrid视图单元中添加工具提示文本?

How do I add tooltip text in datagrid view cell in vb.net?

推荐答案

也许这取决于您的Visual Studio版本...但是我有一些通过遍历网格中的行来设置工具提示的代码,当它找到要向其中添加工具提示的列时,我就对其进行设置. (我在页面上也有一个Tooltip控件...但是我认为您不需要它来使它正常工作.)我使用VS2008.

Maybe it depends on your version of Visual Studio...but I have some code that sets tooltips by looping through the rows of a grid, and when it finds the column I want to add a tooltip to, I just set it. (I also have a Tooltip control on the page...but I don''t think you need it for this to work.) I use VS 2008.

For Each dgvr as DataGridViewRow In dgvGrid.Rows
    dgvr.Cells("ColumnThatNeedsToolTip").ToolTipText = "This is the tooltip!"
Next



我运行它的Form的Load Event,但是如果网格的可见性设置为false,则必须在它再次可见后运行它.您可能需要在使用过滤器后重新运行它.



I run it the Form''s Load Event but if the grid''s visibility is set to false you''ll have to run it after it''s visible again. You may have to rerun it after using a filter.


您不能按单元格添加它,但是可以将其添加到DataGridView中,然后必须对单元格进行热跟踪鼠标悬停(CellMouseEnter和CellMosueLeave事件)并根据需要更新工具提示.
You can''t add it by cell, but you can add it to the DataGridView, then you have to hot-track the cell the mouse is over (CellMouseEnter and CellMosueLeave events) and update the tooltip however you want.


或者您可以处理CellToolTipTextNeeded事件并将单元格值添加到此处的工具提示中:

Or you could handle the CellToolTipTextNeeded event and add the cell value to the tooltip in there:

Private Sub gvw_CellToolTipTextNeeded(ByVal sender as object, ByVal e As System.Windows.Forms.DataGridViewCellToolTipTextNeededEventArgs) Handles gvw.CellToolTipTextNeeded

e.ToolTipText = gvw.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString

End Sub


这篇关于在vb.net中的窗口应用程序的datagrid单元中显示工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆