Is there a way on the ultragrid (or wingrid) to set the tooltip width so that it only fits to the width of the column that is being hovered over? Currently it expands to the entire screen and I have some users who were wondering if this could be altered.
Any examples are certainly appreciated (C#).
Thanks!
Our ToolTipInfo struct, which the grid uses to display the cell tooltips, exposes a 'MaxWidth' property, which allows you to restrict the width, but not force it any bigger. You could use this mechanism to prevent the tooltip width from getting any larger than the width of the column, but you would not be able to force it to that with when there is not enough text in the tooltip.
There is no publicly exposed property or event that gives you access to this struct, but I think you might be able to work around that. The UIElement class exposes a settable property, ToolTipItem, which is of type Infragistics.Win.IToolTipItem, so you could use the IUIElementCreationFilter interface (handle the AfterCreateChildElements method) to intercept the initialization of these elements, and then set the ToolTipItem property of the CellUIElements to a class that implements the IToolTipItem interface. That interface only exposes one method, GetToolTipInfo, which passes you a reference to the CellUIElement, and a ToolTipInfo struct.
You may have arrived at the conclusion by now that this is too much work for the requirement, so you might alternatively want to submit a feature request for a property that allows you to control this.
It doesn't sound like too much work, it just sounds a little out of my league right now. I understand the concepts, but I'm afraid how to apply all of this.
I didn't see AfterCreateChildElements as part of the WinGrid or Ultragrid events, so I assume it's an event of the ToolTipItem?
I don't expect you to do the work for me, but any further direction you can give is certainly appreciated.
AfterCreateChildElements is a method on the IUIElementCreationFilter interface.
Check out this post:
Grid's built-in tooltip is excessive in merged columns - Infragistics Community
The goal here is a lot more complex than you need - you just need to set the MaxWidth. But it should point you in the right direction.
I have circled back to this and had another question. I altered the code a little bit and I can see it firing and working to some degree.
In the AfterCreateChildElements method I changed the code to the following:
if (parent is CellUIElement) { UltraGridColumn column = parent.GetContext(typeof(UltraGridColumn)) as UltraGridColumn; if (column != null && column.Key == "MyColumn") { parent.ToolTipItem = new MergeCellToolTipItem(parent.ToolTipItem); } }
In the method GetToolTipInfo I added the following line:
newToolTipInfo.MaxWidth = 15; // low value just to confirm that this works
I can debug and see the code firing. But, the MaxWidth property doesn't appear to be doing anything. I can also comment out some of the other code in GetToolTipInfo and verify that the commented code has an effect on the tooltip in question (so I know it is working on my tooltip).
Hopefully I am missing something simple here. Thanks for your help.
It looks like MaxWidth and Size are not honored in this case, because the grid is creating the tooltips based on the editor in the cell. So there's probably nothing you can do about that.
The other option would be to turn off the tooltips in the grid entirely and then use the UltraToolTipManager component to show tooltips for the grid yourself. That way you have total control of the tooltips.
Using this:
newToolTipInfo.Size = new Size(50, 50);
Width again appears to be ignored. I can control height with whatever I want. Width on the other hand is another story.
Any other things to try or am I dead in the water?
Hmmm. I think there are some cases where MaxWidth is not honored. Perhaps this is one of them - in which case, maybe you can set the Size instead. Of course, that leaves you with the problem of determining the correct height, and there's really no easy way to do that.
I'd be curious to know if Size works, though.