Click here to Skip to main content
15,920,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I add tooltip text in datagrid view cell in vb.net?
Posted
Updated 30-Aug-10 5:25am
v2
Comments
Dalek Dave 30-Aug-10 11:25am    
Minor Edit for Grammar.

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.

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


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.
 
Share this answer
 
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.
 
Share this answer
 
Or you could handle the CellToolTipTextNeeded event and add the cell value to the tooltip in there:

VB
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
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900