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'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.
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 believe I have it working now. It was the order of statements. Before I had 'PerformAction.EnterEditMode' and then 'grid.ActiveCel = ...' which didn't work. When I reversed these statements, it works. Thanks for your help.
And FormatFormulas is putting each cell into edit mode before it tries to access the selection?
If that's the case, I'm not sure why it's not working. Can you post a small sample project demonstrating the issue?
i have a method FormatFormulas() that goes through each grid row to format the cell.
I tried adding this.BeginInvoke(new MethodInvoker(this.FormatFormulas)); at the end of my Form_Load event and still get the 'Editor must be in edit mode' error.
Hi,
To put the cell in edit mode, you can use grid.PerformAction(EnterEditMode).
However, this will not work in certain events like the Form_Load event, because you cannot set focus to a control inside this event. So you might need to use a BeginInvoke to create a delay.
I'm trying to format the entire Cell since I would have to do this when displaying an existing text when the screen first opens. I set the cell to the ActiveCell, put the grid in EnterEditMode, set the FormattedLinkEditor, but when i try to set the editor.Value or SelectedText to the grid cell's, I get 'Editor must be in edit mode' and I can't figure out the syntax to do that-- the Embeddable UIElement part.