Click here to Skip to main content
15,887,302 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hello All,

This is my first post on this site, finally after having tried all of my resources I just want to know if what I want to do is possible.

Before this post gets flagged for duplication I want to mention a specific detail. Let me explain below (why it isnt a duplicate post!):

I currently have places in my application where, if the user hovers over certain text inside a RICHTEXTBOX, depending on if he hovers over a certain key word inside the control, a tooltip is displayed.

Now, they have asked me to implement this same type of functionality, for one of the datagridviews that we have, where inside a certain column, the cells of that column should have this same functionality of mouse hover on a certain key word inside the cell.

Usually, you only have the hover functionality(tooltip) for the whole cell content and as far as I know, it is not available for individual Key words inside a cell.

All I want to know is that, is there a feasible way to do what I need to do?
Aditionally, I am working on windows forms application under VB.net.

All help is appreciated.
Thank you!
Posted

1 solution

There's no "standard" way to do that, but (although I haven't tried) it shoudl be possible.
There is a DataGridView.CellToolTipTextNeeded Event[^] which allows you to set the ToolTip text "on the fly". The complication will be working out which word you are over!
That's probably going to need a bunch of calls to MeasureString and a degree of trial and error to get right.

But yes, with some effort it should be possible.
 
Share this answer
 
Comments
OriginalGriff 11-Sep-15 11:10am    
Something similar will probably work - except there is no "Get word under mouse" function for DGVCells.
There is a GetCharIndexFromPosition function for textboxes though, and you might be able to use that if you "fake" a displayed textbox with the same dimensions, font, alignment, and text as the cell. I haven't tried that, so I don't know how well it would work, but it's probably worth a try given how much of a PITA it is to get MeasureString to be accurate for all fonts.
Member 11169882 11-Sep-15 11:19am    
Okay, that sounds like a plan. Ill accept you solution! :D thanks
Member 11169882 11-Sep-15 11:20am    
yes the getwordunermouse was my own function which uses getcharindexfromposition
Member 11169882 11-Sep-15 11:05am    
Thanks for your comment sir, indeed, the hardest part is getting the word under the mouse for which I had developed a special function that worked with RichTextBoxes, I would pass in my richTextBoxControl as sender, and then pass in the point (as drawing point) which I had obtained using PointtoClient.

Here is some code exerpt for demonstration: the

If CType(sender, STCRichTextBox).Name = "StcRichTextBoxEnglish" Then
'ToolTip1.RemoveAll()
Dim point As New Point(StcRichTextBoxEnglish.PointToClient(Cursor.Position).X, StcRichTextBoxEnglish.PointToClient(Cursor.Position).Y)
curWord = StcRichTextBoxEnglish.GetWordUnderMouse(CType(sender, System.Windows.Forms.RichTextBox), point)
ElseIf CType(sender, STCRichTextBox).Name = "StcRichTextBoxFrench" Then
'ToolTip1.RemoveAll()
Dim point As New Point(StcRichTextBoxFrench.PointToClient(Cursor.Position).X, StcRichTextBoxFrench.PointToClient(Cursor.Position).Y)
curWord = StcRichTextBoxFrench.GetWordUnderMouse(CType(sender, System.Windows.Forms.RichTextBox), point)
End If


Im wondering that if something similar is possible with a cell, then I might end up giving it a shot. So far I have been out of luck.

If you have some insigths regarding this, do let me know. For now I will see how far I get lol!

Again, really appreciate your comment and help. Cheers

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