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);
Nevermind the last question there. I did this and removed the logic to track the mouse move, etc. and it shows the tool tip on hover beautifully.
private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e) { for (int cellCounter = 0; cellCounter < e.Row.Cells.Count; cellCounter++) { e.Row.Cells[cellCounter].ToolTipText = e.Row.Cells[cellCounter].Value.ToString(); } }
ow if I can just get the other value populated I'll be able to get back to bothering you about how to sort the group by rows in other than alphabetical order!
Thanks much!
Allen
Hey Mike,
I am still trying to figure out the cleanest way to be able to display both of my values - the one that needs to appear in the cell and the one that needs to appear in the tool tip on hover. I thought I could store the key they both share in the value and then replace the value at row initialization time but I'm getting an error that seems to indicate I cannot update the cell value because the column is read-only. I thought maybe the issue was me trying to pass a string value to the cell's SetValue which takes an object so I changed that to cast the string as an object but that doesn't help matters any. What am I doing wrong? Can I not update the cell value at time of row initialization?
Thanks.
private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e) { for (int cellCounter = 0; cellCounter < e.Row.Cells.Count; cellCounter++) { string tempGuid = e.Row.Cells[cellCounter].Value.ToString(); int thisIndex = HoverTextsList.IndexOf(tempGuid) + 1; if (thisIndex > 0) { e.Row.Cells[cellCounter].ToolTipText = HoverTextsList[thisIndex]; e.Row.Cells[cellCounter].SetValue((object)ValueTextsList[thisIndex],false); } } }
System.Data.ReadOnlyException: Column '08/12/2009' is read only. at System.Data.DataRow.set_Item(DataColumn column, Object value) at System.Data.DataRowView.SetColumnValue(DataColumn column, Object value) at System.Data.DataColumnPropertyDescriptor.SetValue(Object component, Object value) at Infragistics.Win.UltraWinGrid.UltraGridRow.SetCellValue(UltraGridColumn column, Object val, Boolean suppressErrorMessagePrompt, Boolean throwExceptionOnError, Boolean fireDataChanged, Boolean fireCellUpdateEvents) at Infragistics.Win.UltraWinGrid.UltraGridRow.SetCellValue(UltraGridColumn column, Object val, Boolean suppressErrorMessagePrompt, Boolean throwExceptionOnError, Boolean fireDataChanged) at Infragistics.Win.UltraWinGrid.UltraGridRow.SetCellValue(UltraGridColumn column, Object val, Boolean suppressErrorMessagePrompt, Boolean throwExceptionOnError) at Infragistics.Win.UltraWinGrid.UltraGridCell.SetValueInternal(Object value, Boolean suppressErrorMessagePrompt, Boolean fireInitializeRow, Boolean throwExceptionOnError, Boolean fireDataChanged) at Infragistics.Win.UltraWinGrid.UltraGridCell.set_Value(Object value) at Infragistics.Win.UltraWinGrid.UltraGridCell.SetValue(Object value, Boolean storeInUndoStatck, Boolean checkForReadOnlyCells) at Infragistics.Win.UltraWinGrid.UltraGridCell.SetValue(Object value, Boolean storeInUndoStatck) at CTCAFlowsheetTab.frmCTCAFlowsheetTab.ultraGrid1_InitializeRow(Object sender, InitializeRowEventArgs e) at Infragistics.Win.UltraWinGrid.UltraGrid.OnInitializeRow(InitializeRowEventArgs e) at Infragistics.Win.UltraWinGrid.UltraGrid.FireEvent(GridEventIds id, EventArgs e) at Infragistics.Win.UltraWinGrid.UltraGrid.FireInitializeRow(InitializeRowEventArgs e) at Infragistics.Win.UltraWinGrid.UltraGridRow.FireInitializeRow() at Infragistics.Win.UltraWinGrid.RowsCollection.FireInitializeRow(IList rows) at Infragistics.Win.UltraWinGrid.RowsCollection.SyncRowsHelper(IList boundList) at Infragistics.Win.UltraWinGrid.RowsCollection.SyncRows() at Infragistics.Win.UltraWinGrid.RowsCollection.EnsureNotDirty() at Infragistics.Win.UltraWinGrid.RowsCollection.GetEnumerator() at CTCAFlowsheetTab.frmCTCAFlowsheetTab.FillGrid(String storedProcName)
Hi Allen,
I'm not sure I am following what you are trying to do here. If you set the value on the cell to something other than the original key value, then you will lose the key value and the next time InitializeRow fires, it won't be there.So that doesn't seem like a good idea.
If you have a key value in a cell and you want to show something else and also have a tooltip with different information, then what I would do is hide the key column and add an unbound column to the grid.
Then you use InitializeRow to set the value and the ToolTipText on the unbound column based on the value of the key column. That way you don't lose the key value and can still display 2 different pieces of information based on that key.
Hi Mike. Thanks for the response. I'm sure I'm not following you. :-)
What I'm trying to do is store one value in a cell and another value in the tool tip for that cell. These values are known at the time the grid is filled so initializerow will only be fired while the values are known. If the grid is reloaded then the stored procedure will be called again and the values may be different from the last time the grid was filled but that will again be known when initializerow is called.
The two values for each cell are different than the values of any of the other cells in a particular column and the two values for a particular cell are not related to each other except that they are part of the same row from the result set which is being processed as the rows are being added to the grid. Columns have already been created and added to the grid before the rows are added.
Are you saying there is no way to set the value of the cell from the initializerow event?
Are you saying that I need to create an unbound column for every column in the grid and basically to have two cells for each cell and then somehow grab the value from the cell in the unbound column to display in the tool tip on hover over the cell in the bound column?
Thanks again.
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.
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?