Anyone,
I'm trying to add a tooltip to my ultragrid when the user hovers over a cell. My first step was to just get the tooltip to display when the user was over a cell and then I was going to check for a specific cell in the next step. I can't get the following code to work to display the cell. I have the ultraToolTipManager on the form.
My code is below. Thanks, Kris
{
// Get the cell location.
// Get a refernce to the cell.
// Make sure the mouse is over a cell.
new Infragistics.Win.UltraWinToolTip.UltraToolTipInfo("Click Button", ToolTipImage.Info, "Delete Record", DefaultableBoolean.True);
// Display the tooltip.
ultraToolTipManager.SetUltraToolTip(igrdAgentPool, tipInfo);
ultraToolTipManager.ShowToolTip(igrdAgentPool);
}
else
ultraToolTipManager.HideToolTip();
What event is this code in?
GetChildAtPoint will not work. Thie method gets a child control, but a cell is not a control. To get the cell at a particular point in the grid, you should be using the GetContext method off of the UIElement. There are lots of KB articles on this:
Knowledge Base Results - ElementFromPoint
Mike,
Thanks. The GetContext was what I was missing. I did find a lot of examples in the KB that is where I got the code I was using. Here is the code that I am using now.
Thanks a lot Kris.
// Get a refernce to the column.
// Show the tooltip only when it is over the "Delete" column.
new Infragistics.Win.UltraWinToolTip.UltraToolTipInfo("Click button to delete record.", ToolTipImage.Info, "Delete Record", DefaultableBoolean.True);
// Set the tooltip and it will be displayed automatically based on the tooltip manager settings.
//ultraToolTipManager.ShowToolTip(igrdAgentPool);
Don't know whether it is best to create a new post or to pose my questions in a post that I think is pertinent...
I'm trying to display a tooltip on hover over a cell. I need to know what cell it is because I need to display one value in the cell and an alternate value (particular to that cell) in a tool tip over the cell when the user hovers the mouse pointer over any cell.
I tried using if (e.Element is Infragistics.Win.UltraWinGrid.CellUIElement) from above but my element is not a CellUIElement on hover over a cell. I get RowUIElement followed by RowCellAreaUIElement and some others before it settles down but not CellUIElement. Why is that? Can I somehow use RowCellAreaUIElement to indicate I'm in a cell and can I also determine which cell from it?
I've tried approaching like this...
Infragistics.Win.UIElement myUIElement = ultraGrid1.DisplayLayout.UIElement.ElementFromPoint(new Point(e..X, e.Y));
...but it seems I don't have any coordinates in the MouseEnterElement event...I get the following error for both X and Y:
'Infragistics.Win.UIElementEventArgs' does not contain a definition for 'X' and no extension method 'X' accepting a first argument of type 'Infragistics.Win.UIElementEventArgs' could be found (are you missing a using directive or an assembly reference?)
Am I missing an assembly reference? I've got:
using Infragistics.Win;using Infragistics.Win.UltraWinGrid;
How to determine on hover a) that I'm in a cell and b) what cell I'm in.
Thanks.
Allen
Hi Allen,
Have you considering just using the ToolTipText property on the cell? The InitializeRow event would be an excellent place to set this property.
I guess I couldn't get my head around adding unbound columns. I add my columns before I do any work with the rows and it seems to me I'd need to duplicate each column and store the hover text into each of the cell values for that extra column and then at row initialization I'd copy that value (current cell index plus 1) back to the tool tip for the column / cell I want to display. Instead I added logic to save off the value needed on hover to a list preceded by a concatenation of the column name and the row name and the value of the cell being added to the row so that I can cycle back through that list at row initialization time to load the appropriate hover values into the tooltiptext. Seems to work well.
Thanks Mike for the idea to use the InitializeRow event and the ToolTipText. Most helpful.
I don't care about the value of the index. I'm only returning it with the result set to help me keep track of these two discrete values that need to be associated with a particular cell. As soon as I get the two cell values into their respective virtual locations, I'm done with that index value and don't ever need to see it again.
I guess I could try saving off the date value (so I'd know the colum) and the cell value and the row identifier so that I can go through each column at intializerow time and add the tool tip value based on being in that column with that value.
I'll read your post more closely when I have more time.
Thanks,
I guess what you are describing might technically be possible, but it seems like a bad idea, since you will be losing the original stored index and there's really no good reason to.
For example.. suppose I have a table with a single integer column like so:
1
2
3
If I bind this to the grid, the grid will show exactly what's in the table.
Now... I can handle InitializeRow and, based on the value of the cell (1, 2, or 3), I could set the ToolTipText on that cell.
I could also change the value of the cell. So suppose I change 1 to 10, 2 to 20, and 3 to 30.
The next time InitializeRow fires for the first row, the cell will have a 10 in it, and I have no corresponding item for 10 in my list of tooltip texts.You could get around this by checking e.ReInitialize and only setting the cell value and the ToolTip when it's false (the row is initialized for the first time). But that's not the only issue.
Another problem is... suppose I want to change the 1 into "A". I can't do that, because it's an integer column.
It seems to me that the safest thing to do is to simply hide this column and display an unbound column in the grid. The unbound column could be a string, so I can set the text to anything I want - I am not limited by the data type of the original column. Also, I don't have to worry about what happens if the value in the real data column changes. InitializeRow will fire again and update the unbound column's value and tooltip automatically.
Yes I am saying that I want to load a value into the tool tip and a different value into the cell. Maybe that is easy to do when I am running through the result set rows to create that dataset row but I don't see how since I don't have access to the cells in the row until I've created the row.
So...I thought I would store an index in the value for each cell and also create two lists, one for the cell value and one for the tool tip value keyed on that index.
At the time of row initialization, I would look at the value I'd placed in the cell and look that up in the two lists and then I'd add the tool tip value for that cell and change the value (now that I've got the tool tip added by way of the index) of that cell to what I really need the value to be (the value stored in the other list by that index).
Let's take the rainfall example again:
I've got a bunch of date columns defined and now I'm going through the actual values one state at a time and creating rows for each state. I have a rainfall amount and a calculation that was used to produce that particular rainfall amount on that date. I want to display the rainfall amount in the cell and I want to display the calculation that was used to come to that amount on hover over the cell. I need to get both values stored for each cell somehow and I don't see how to do that for the tool tip value before I've added the row - and I won't add that row until I've gone through all the rainfall amounts for each date for that state.
How do I store the rainfall amount as the cell value and the calculation used in the tool tip for the corresponding cell?
allenovereem said:What I'm trying to do is store one value in a cell and another value in the tool tip for that cell.
I'm getting even more confused. You seem to be contradicting yourself here.If all you want to do is display a tooltip in a cell that is different from the actual text in the cell, then you just set the ToolTipText on the cell. You can do this in InitializeRow. It's very simple.
But you seem to say quite clearly in your previous post that this is not all you need to do. You said that you also want to change the actual value of the cell in addition to the tooltip. That's where I think you will run into problems.
allenovereem said:Are you saying there is no way to set the value of the cell from the initializerow event?
No, I am not saying that. But if you set the Value of a cell in InitializeRow, or any other event, you lose the original Value of the cell. If the value in a cell is "123", and you change that value to "321", then the next time InitializeRow fires, you will get "321". It doesn't make sense to change the value of the cell and lose the original value, because then you will end up processing the new value and change the cell's value and tooltip again.
Are you under the impression that InitalizeRow only fires once for each row? Because that is not the case. InitializeRow will fire any time any value in the row changes, when the row is first creating, and may fire when the grid gets certain notifications from the data source.