This is a migrated thread and some comments may be shown as answers.

How do I set ToolTip of data cells to their content?

10 Answers 933 Views
GridView
This is a migrated thread and some comments may be shown as answers.
ClausDC
Top achievements
Rank 1
Iron
Iron
Iron
ClausDC asked on 13 Jul 2010, 01:30 PM
How do I set the ToolTip of a data cell to the content of the cell or at least to a string based content, if the cell has a string-based content?
This would be useful, if the cell width is to small to display the whole content.

I already have this style:

<Style x:Key="CellStyle1" TargetType="{x:Type tk:GridViewCell}">
                <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Content.Text}" />
            </Style>

(I have labels as content in all my cells).

This works in principle, but I always get lots of data errors in the debug window output, because there seem to be some automatically generated cells who don't have my Label in it.

"
System.Windows.Data Error: 40 : BindingExpression path error: 'Text' property not found on 'object' ''String' (HashCode=757206908)'. BindingExpression:Path=Content.Text; DataItem='GridViewCell' (Name=''); target element is 'GridViewCell' (Name=''); target property is 'ToolTip' (type 'Object')
"

Any way to get rid of these errors?

Is there a better way to set the ToolTip of data cells to the content of cells?

Thanks

10 Answers, 1 is accepted

Sort by
0
Ваня
Top achievements
Rank 1
answered on 13 Jul 2010, 02:33 PM
Hello,ClausDC

According to me it is better to add the tooltip to the rows using DataTemplate,see how to do that:
http://www.telerik.com/help/wpf/gridview-how-to-create-row-tooltip.html


Hope this helps!
0
Accepted
Maya
Telerik team
answered on 16 Jul 2010, 01:00 PM
Hi Claus,

Another possible approach that will add a ToolTip for every cell is to make a slight change into the definition of your style like follows:

<Style TargetType="{x:Type telerik:GridViewCell}">
     <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Value}" />
</Style>

 
All the best,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
ClausDC
Top achievements
Rank 1
Iron
Iron
Iron
answered on 22 Jul 2010, 07:58 AM
This doesn't work.

If I have a big table where I scroll around (vertically and/or horizontally), no ToolTips are shown anymore.

I end up with a behaviour that only the first and last column do show ToolTips for each cell.

I suspect that this has something to do with how GridView dynamically loads data to the view?
0
Maya
Telerik team
answered on 22 Jul 2010, 04:42 PM
Hello ClausDC,

We will investigate the issue and we will inform you as soon as we are able to provide a proper solution. For the time being the a possible workaround is to disable the ColumnVirtualization. 
Please excuse us for the inconvenience caused.

Sincerely yours,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
rishi
Top achievements
Rank 1
answered on 02 Mar 2011, 11:05 AM
Thanks Mr,
<Style TargetType="{x:Type telerik:GridViewCell}">
     <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Value}" />
</Style>

its working fine now.

Claus its working fine make sure you are doing it right. Have a look again, might be you are missing some thing.
Good Lucj
Regards
0
Rodney Foley
Top achievements
Rank 1
answered on 13 May 2013, 09:48 PM
I can also confirm this works. 

However I have a follow up question related to this. How can you have this ToolTip only display if the cell the mouse is hovering over is truncated? Otherwise it not very useful to display what is fully visible in a cell also in a tooltip.
0
Maya
Telerik team
answered on 13 May 2013, 10:31 PM
Hi Rodney,

You can try to create ToolTip template selector, verify whether the text is longer than the width of the cell for example and display the ToolTip if necessary. 

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Rodney Foley
Top achievements
Rank 1
answered on 14 May 2013, 04:12 PM
Could you provide an example by chance?
0
Maya
Telerik team
answered on 15 May 2013, 03:11 PM
Hi Rodney,

You can check out this demo and this article for more information. You can verify what is the value of the property you want and the with of the cell for example from the arguments of the SelectTemplate method.

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
ClausDC
Top achievements
Rank 1
Iron
Iron
Iron
answered on 21 Jun 2013, 03:15 PM
Yes, it does seem to work now.
Tags
GridView
Asked by
ClausDC
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Ваня
Top achievements
Rank 1
Maya
Telerik team
ClausDC
Top achievements
Rank 1
Iron
Iron
Iron
rishi
Top achievements
Rank 1
Rodney Foley
Top achievements
Rank 1
Share this question
or