display tooltip on mouse hover in cell

This post has 12 Replies | 5 Followers

akatsifos
Points 170
Replied On: Tue, Oct 14 2008 7:34 AM

Hello

how is it possible to read cell value and display tooltip on mouse hover in a grid .

i tryed the

Point mousePoint = new Point(MousePosition.X, MousePosition.Y);

UIElement element = ultraGrid1.DisplayLayout.UIElement.ElementFromPoint(mousePoint);

UltraGridCell cell = element.GetContext(typeof(UltraGridCell)) as UltraGridCell;

 

if (cell != null)

{

MessageBox.Show(cell.Row.Index.ToString() + " " + cell.Column.Key);

}

 

but it does not work

  • Post Points: 35
P0110X
Points 35
Replied On: Tue, Oct 14 2008 9:50 AM

 Casually, there is another post where they suggest to do the following:

//assuming you have a ToolTip control

 void grid_MouseLeaveElement(object sender, Infragistics.Win.UIElementEventArgs e)
        {
            toolTip.SetToolTip(poolGrid, null);
        }

        void grid_MouseEnterElement(object sender, Infragistics.Win.UIElementEventArgs e)
        {
            if (e.Element is EditorButtonUIElement)
            {
                EditorButton button = e.Element.GetContext(typeof(EditorButton)) as EditorButton;

                if (button.Tag != null)
                    toolTip.SetToolTip(grid, button.Tag.ToString());
            }
        }

  • Post Points: 5
Mike Saltzman
Points 464,760
Infragistics Employee
Replied On: Tue, Oct 14 2008 10:15 AM

My guess is that MousePosition returns you the position of the mouse in screen coordinates, not control coordinates. You can probably convert the coords using grid.PointToClient. Or you can use the MouseMove even and use e.X and e.Y. 

Or, you could use grid.DisplayLayout.UIElement.LastElementEntered, instead of ElementFromPoint.

Or, you could use MouseEnterElement and MouseLeaveElement, as suggested above. :)

Mike Saltzman

Manager - Windows Forms Development

Infragistics, Inc.

  • Post Points: 40
vrn
Points 9,364
Replied On: Tue, Oct 28 2008 1:52 PM

 Mike, using the MouseEnterElement and MouseLeaveElement approach, can one introduce a tool tip delay i.e. it takes some time before the tool tip shows? Would one just sleep for a few millisecond and then cause the tooltip to show?

  • Post Points: 20
Mike Saltzman
Points 464,760
Infragistics Employee
Replied On: Wed, Oct 29 2008 9:46 AM

Well, if you use the ShowToolTip method, then the tooltip will show up immediately.You could use a Timer to introduce a delay, I suppose.

Another option would be to change the ToolTip on the control based on the location of the mouse. You would do this using the UltraToolTipManager.GetUltraToolTip method. And then you can set properties on the UltraToolTip settings for that control. This way the UltraToolTipManager would handle the delay for you.

Mike Saltzman

Manager - Windows Forms Development

Infragistics, Inc.

  • Post Points: 55
vrn
Points 9,364
Replied On: Fri, Oct 31 2008 3:00 AM

 Mike,

Two questions regarding two unrelated requirements:

- I have a column with icons displayed representing some underlying values. I would like a tooltip on the icon to say what it means (eg: red dot - status trouble, green dot- status fine, etc) What is the best approach to do this? Is there a way to tell the tooltipmanager that I want tooltip for a complete grid column and tell it what the various tooltips are for each underlying values of icon?

- Unrelated to the above question, I have another requirement to show tooltip for each cell but with a delay. I found from previous posts that it is possible to set tooltip on individual cells using the tooltip property but it shows without delay. For getting the delay, based on your suggestion, I would need to use the ToolTipManager

    a) what control would I associate the tooltipmanager with

    b)  To set the tooltip value, I have to trap the mouse enter event, find the underlying cell and set the tooltip value?

 

 Thanks!

  • Post Points: 20
Mike Saltzman
Points 464,760
Infragistics Employee
Replied On: Mon, Nov 3 2008 10:00 AM

vrn:
- I have a column with icons displayed representing some underlying values. I would like a tooltip on the icon to say what it means (eg: red dot - status trouble, green dot- status fine, etc) What is the best approach to do this? Is there a way to tell the tooltipmanager that I want tooltip for a complete grid column and tell it what the various tooltips are for each underlying values of icon?
 

What you would do is trap the MouseMove event of the grid and determine which cell the mouse is over. Then you would set the text on the ToolTip for the grid based on the location of the mouse. This is pretty much how tooltips work for every control. The tooltip is associated with the entire control, so if you want different tooltips for different areas, you have to change the tooltip as the mouse moves. 

vrn:

    a) what control would I associate the tooltipmanager with

The UltraGrid control.

vrn:

    b)  To set the tooltip value, I have to trap the mouse enter event, find the underlying cell and set the tooltip value?

You would use the MouseMove event. Or maybe MouseEnterElement. Then you have to determine what the mouse is over. You do this using the ElementFromPoint method. Check out the Infragistics Knowledge Base and do a search for "ElementFromPoint". There are a whole bunch of articles on using this technique to get a cell, row, or column from a mouse point. 

 

 

Mike Saltzman

Manager - Windows Forms Development

Infragistics, Inc.

  • Post Points: 20
vrn
Points 9,364
Replied On: Tue, Nov 4 2008 4:00 AM

[quote user="[Infragistics] Mike Saltzman"]You would use the MouseMove event. Or maybe MouseEnterElement. Then you have to determine what the mouse is over. You do this using the ElementFromPoint method. [/quote]

Is it a problem if a set of  related grids share an instance of the tooltipmanager?

  • Post Points: 20
Mike Saltzman
Points 464,760
Infragistics Employee
Replied On: Tue, Nov 4 2008 11:33 AM

No, not at all. The ToolTipManager can handle any number of controls. You just need to make sure that you are setting the tooltip on the right grid control. 

Mike Saltzman

Manager - Windows Forms Development

Infragistics, Inc.

  • Post Points: 5
vrn
Points 9,364
Replied On: Sun, Jun 14 2009 6:53 PM

Mike,

You said

[quote user="[Infragistics] Mike Saltzman"]

Well, if you use the ShowToolTip method, then the tooltip will show up immediately.You could use a Timer to introduce a delay, I suppose.

Another option would be to change the ToolTip on the control based on the location of the mouse. You would do this using the UltraToolTipManager.GetUltraToolTip method. And then you can set properties on the UltraToolTip settings for that control. This way the UltraToolTipManager would handle the delay for you.

[/quote]

 

It worked but  I get a tool tip to show ONLY the first time I enter a cell in that Grid. After that the only way to make the tooltip show is to either hover over outside that Grid and re-enter. Another way (little weird) is to click on another row in the same Grid and then hover over some cell. Those are these only two casesThe debugger tells me the MouseEnterElement handler is being invoked each time I hover over to a new cell.

On MouseEnterElement:

this.ultraToolTipManager1.InitialDelay = 500;           
Infragistics.Win.UltraWinToolTip.UltraToolTipInfo toolTipInfo = this.ultraToolTipManager1.GetUltraToolTip((UltraGrid)sender);
toolTipInfo.ToolTipText = "hello"; // cell specific information here
//this.ultraToolTipManager1.ShowToolTip((UltraGrid)sender); 

If I uncomment  the ShowToolTip method call above, I get the tooltip to show for each cell immediately as soon as I enter that cell.

What am I doing incorrect?

Thanks!

  • Post Points: 20
Mike Saltzman
Points 464,760
Infragistics Employee
Replied On: Mon, Jun 15 2009 11:07 AM

There's a sample included with the NetAdvantage SDK that does exactly what you are trying to do.

Samples\WinMisc\CS\ToolTipManager\ToolTips with Context CS

The sample uses a base class with a method called PrepareTooltip and then derives a class for the grid that overrides this method. So you could copy these two classes into your application and then just handle the PrepareToolTipMethod on the "ToolTipContextHelperForGrid" class.

Mike Saltzman

Manager - Windows Forms Development

Infragistics, Inc.

  • Post Points: 20
ilovela
Points 1,255
Replied On: Mon, Feb 1 2010 5:19 PM

Sorry I'm new to Infragistics, where can I find the "samples" folder   ? 

  • Post Points: 5
ilovela
Points 1,255
Replied On: Mon, Feb 1 2010 5:27 PM

I just found it, thank you  Mike

  • Post Points: 5
Page 1 of 1 (13 items) | RSS