Hi!
If I have an UltraGrid that is bound to a class with Properties A and B and thus have the grid columns A and B; how can I use the cell values from column A in the formatting of the cell values of column B (or an unbound column C)?
From this data:
Col A | Col B
=============
ValA1 | ValB1
ValA2 | ValB2
I want to be able produce this display output:
ValA1 | "ValA1 ValB1"
ValA2 | "ValA2 ValB2"
Hello Ulf,
Thank you for your feedback and for sharing this with us.
Please feel free to let me know if a question about our toolset comes up on your mind.
Thanks Mike and Boris!
I added extra columns (of datatype string) for the combined data, and setting the cell value in the InitializeRow event handler works just fine. I used the Text property [such as e.Row.Cells("ColB").Text] of the cells that I take the values from.
(As for the slow visual update of the calculations, I now open the actual three band grid fully collapsed [which is reasonable from a user perspective]. This means that there are a lot fewer calculated cells that are viewable upon setting the data source, and the visual rendering of the values of these is fast enough for an okay user experience.)
InitializeRow might fire initially before the formula is calculated, but it should fire again after the formula calculation is completed and the value of the cell changes.
You understood me perfectly. That was exactly what I intended. Thank you!My brain was a bit "fried" after working with Formulas and Formats for a couple of hours so missed this obvious solution, and I was looking for some way of doing it using the Formula, or Format, or some other, property.
However, since I am using a Formula to calculate that the values (ValB1, ValB2, ...) of ColB, it turns out that these values (ValB1, ValB2, ...) are not yet present at the InitializeRow event firing time, so I believe that I can't use the InitializeRow approach together with the CalcManager/Formula feature. Am I correct in this?
(I will probably leave the Formula approach and add already calculated properties to the class unless I am incorrect about the InitializeRow and Formula calculation timing. Also the calculations seem slow - or at least the visual update of the calculated values in the grid appears slow - which is a bit of a turn off. :-| )
It should be noted that the code Boris posted here will not simply format the display of Col B, it will actually change the value of Col B. And this won't work very well, because if InitializeRow fires for the same row more than once (which it will), then it will keep appending to the same text. What you really need to do here is hide the real Col B and replace it with an unbound column and use that column to display the combined values.