I have an UltraGrid that has one column that may have a lot of data in it to display (but not edit). I set the CellActivation = Activation.ActivateOnly and VertScrollBar = true. This works fine. When the user clicks on a cell with a lot of data the vertical scroll bar appears as expected however the fomatting in the cell is lost. How can I retain the formatting while keeping the vertical scroll bar functionality. I tried to post a before and after screen shot but the site only allowed me to post 1 attachement so here is the after shot.
I am speculating because I don't see anything wrong with the formatting going by the screenshot...When you put a cell into edit mode a TextBox control is displayed therein, and the .NET TextBox does not support GDI+, where cells render this way by default. The result is a different number of characters per line which, if you were relying on the way they look when not in edit mode, would be different when in edit mode. If I misunderstood this please post the before/afer screenshots by zipping them and posting the .zip and we'll try to help.
Hi Brian,
Thanks for your reply and explanation. As you requested I am including before and after screen shots as an attached zip file for your review.
I am wondering if I am stuck with this behavior or is there a viable solution?
Thanks in advance
Omer
Hi Mike,
Sorry for the late reply but just got a chance to look into the text formatting issue that you raised in your last post.
As you mentioned we are indeed storing the text in a database with "\line" character for a new line instaed of "\r\n". The reason for this is that we want to display this text in a rich text box in another part of the application.
So I guess the question is how can I replace the "\line" character with "\r\n" when a user clicks on a cell?
Thanks
Hi Omer,
Okay, so it is, in fact, that inbox TextBox control that is failing to honor the "\line" character. Have you tried \r\n with the RichTextBox? Does it not support this?
If you don't want to change the data, then there are two approaches you could take here. One would be to use an Editor on the grid column with a DataFilter. The DataFilter allowed you to handle the transition of the data between the owner (the back end), the editor (the grid cell), and the display (the screen). In your case, you would probably want to handle the OwnerToEditor and replace "\line" with "\r\n" and then handle EditorToOwner and do the reverse.
The other option basically the same approach in a different way. You could hide the real grid column and add an unbound column to display to the user. Then you could use events of the grid like InitializeRow to read the data in the real column, replace the line break, and set the value on the unbound column. You would reverse this process in BeforeRowUpdate.
Thanks for your reply. As you suggested I used an EditorWithText object and wrote my own DataFilter. Everything works fine now with respect to the new line spacing when I click on the cell however the text formatting is still off. I am attaching a zip file so that you can see what I am talking about. We want to maintain the visual appearance to the user. I am hoping that there is a way to do this. Thanks in advance for all of your help.
Kind regards
Hi,
Are you referring to the difference in the spacing in between characters? This is the difference between GDI+ and GDI text rendering. When the cell is not in edit mode, the grid draws the text using GDI+, which is what DotNet uses. When the cell goes into edit mode, it's showing an Inbox TextBox control which uses GDI.
You will see the same kind of thing if you compare a TextBox to a Label control in DotNet. The Label uses GDI+ and the TextBox uses GDI.
There's no way to get the TextBox to use GDI+, but you could set up the grid to use GDI by setting the TextRenderingMode. The down side of this is that it has performance implications. GDI tends to be a bit slower in DotNet, so if your grid is particularly large or complex, this could slow down your application a little.
OK. Thanks Mike. I tried your suggestion but it didn't seem to make a difference. I guess we wil have to go with what we have.
By the way are there any plans in the future to change this?
The solution in
http://ko.infragistics.com/community/forums/t/18063.aspx
helped me.
Sorry for the late reply. I tried your solution and it helped although it is still not 100%. However this may be good enough for our purposes. I also did NOT use the GDI TextRendering Mode. Thanks for all of your help.
There is now another issue that I was not aware of before and I will post that in a separate thread.
Thanks again
Okay, I see the issue now. It's a pretty subtle change. The first line of text is okay, but after that the text wrapping has to change due to the decreased available width of the cell.
CellActivation doesn't seem to make any difference here, it's just the VertScrollBar that does it.
There are basically two ways you could deal with this.
1) Make the scrollbar show all the time.
2) Leave a space in the cell where the scrollbar would be.
Personally, I think it will probably make the grid look pretty cluttered to have a scrollbar always display in every cell of the column. And in fact, the grid doesn't expose any way to do this in v8.3. If you had the latest version of the controls, you could use the new UltraControlContainerEditor to embed a TextBox into the cell and leave the scrollbar on all the time. But the UltraControlContainerEditor was not available in v8.3.
Leaving a space would have to be done using a CreationFilter and this could be done in v8.3.This is actually a pretty simple CreationFilter.
public class MyCreationFilter : IUIElementCreationFilter { #region IUIElementCreationFilter Members void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent) { if (parent is EditorWithTextUIElement) { UltraGridCell cell = parent.GetContext(typeof(UltraGridCell)) as UltraGridCell; if (cell != null && cell.Column.Key == "Column 0") { EditorWithTextDisplayTextUIElement editorWithTextDisplayTextUIElement = parent.GetDescendant(typeof(EditorWithTextDisplayTextUIElement)) as EditorWithTextDisplayTextUIElement; if (editorWithTextDisplayTextUIElement != null) { Rectangle rect = editorWithTextDisplayTextUIElement.Rect; editorWithTextDisplayTextUIElement.Rect = new Rectangle( rect.X, rect.Y, rect.Width - SystemInformation.VerticalScrollBarWidth, rect.Height); } } } } bool IUIElementCreationFilter.BeforeCreateChildElements(UIElement parent) { return false; } #endregion }
Thanks for your prompt response. I got your app to run by altering the references. The 2 lines of code that you are missing in the ultraGrid1_InitializeLayout function are:
band.Columns[0].CellActivation =
Activation
.ActivateOnly;
band.Columns[0].VertScrollBar =
;
When you include these then the TextRenderingMode doesn't work as expected since the vertical scrollbar takes up some of the width of the cell. Since the dimensions of the cell change then I guess there is nothing that can be done to maintain the text formatting with and without a scrollbar. This is the issue at the heart of the problem.
omerk said: I can't compile your project becuase we do not have v9.2 of the Infragistics2 dlls. The latest version we have is v8.3. Would this make a difference? If not, could you please resend your project using the 8.3 version of these dlls instead?
You can just remove the 9.2 references from the project and add the equivalent 8.3 references.
I can't see any reason why an UltraTextEditor should cause any different in the behavior here. The column will use an EditorWithText by default, so it's essentially the same thing.