I have an UltraGrid with a column that has its style = FormattedTextEditor. I use combo boxes and button selections to populate the column with various text items that essentially define a formula. I'm trying to format it so that different pieces of the formula have different colors. I am using FormattedLinkEditor and am successful doing this as long as I'm appending the pieces sequentially. It save the current Value and appends the newly added formatted value. I'm having trouble inserting a formatted piece in the middle of the formula. I can do it with the text part but it loses the formatting. How do I break up the formatted value into a" part1" and "part2" and insert a new formatted part in between.
Thanks,
Ron
Hi Ron,
I thought you were talking about modifying the text strictly through code, but it sound like you want the user to be able to insert text at the current cursor position. That should be fairly easy using the editor.
Assuming that the current ActiveCell in the grid is a FormattedTextEditor cell, you could do something like this:
UltraGridCell cell = this.ultraGrid1.ActiveCell;Infragistics.Win.FormattedLinkLabel.FormattedLinkEditor editor = (Infragistics.Win.FormattedLinkLabel.FormattedLinkEditor)cell.EditorResolved;editor.SelectedText = "A";
I guess my main issue is determining at what point in the XML to split the Value and how to do that. To get the point to insert, I'm using the grid click or double click in the formatted cell to determine the point (e.Cell.SelStart + e.CellSelLength). This seems to be the point of the cell Text and not the formatted Value. I originally did all this strictly with the Text and it worked okay. Maybe this isn't possible. I also had considered doing the 'rebuild everything' after the Text was inserted and may try to do that or forget about the formatting altogether. Again, is there a way to split the Value into Value pieces, or is this just not a good idea?
I'm a little fuzzy on the problem. The way it works is that you assign the Value of the cell with a string of XML that contains the information including the formatting of the text. So in order to insert something into the middle, you would have to insert the appropriate text into the xml in between the appropriate tags.
There's not enough information in your post for me to guess what you are doing, where you are inserting the text, or why you are losing the formatting. My best guess is that you are inserting the text at the wrong point and you are somehow ending up with corrupted XML.
It seems to me that it would be a lot easier for you to simply rebuild the entire string sequentially rather than trying to modify the existing XML to do an insert. This might create a performance problem, of course, but only if your strings are pretty long.