Hi,
I am trying to add an editable text editor into the header, so that the user can "set" the caption of the header at runtime. However, I am running into two problems:
1. The initial caption of the header isn't set in the text editor.
2. The text editor doesn't enter in edit mode, so I can't enter text.
We are using v7.3
This is my creation filter:
---------------------------------------------
internal class DesignCreationFilter : IUIElementCreationFilter { public DesignCreationFilter() { } public bool BeforeCreateChildElements(UIElement parent) { return false; } public void AfterCreateChildElements(UIElement parent) { try { if (parent is HeaderUIElement) { parent.ChildElements.Clear(); var column = (UltraGridColumn)parent.GetContext(typeof(UltraGridColumn)); var editorText = new EditorWithText(); var editorOwner = new DefaultEditorOwner(); var editor = new EditorWithTextUIElement(parent, editorOwner, editorText, column.Header, true, true, true, false); Rectangle rect = parent.ClipRect; rect.Inflate(-2, -2); editor.Rect = rect; editorText.TextBox.Text = column.Header.Caption; editorText.TextBox.ForeColor = Color.Black; editorText.TextBox.Enabled = true; editorText.TextBox.ReadOnly = false; parent.ChildElements.Add(editor); } } catch (Exception ex) { } } }
Any ideas what could cause this behaviour?
Many thanks!
It would probably be easy to position an UltraTextEditor control over the header, rather than trying to do this using UIElements. The EditorWithTextUIElement is going to be relying on certain owner settings and methods that you don't have access to here. You're just passing in a DefaultEditorOwner here, but that's not going to be enough. You would have to derive a class of your own from EmbeddableEditorOwnerBase and override a bunch of methods and properties.
What I would do is just use the CreationFilter to position an UltraTextEditor control over the HeaderUIElement.
You mean like this?
public void AfterCreateChildElements(UIElement parent) { if (parent is HeaderUIElement) { var column = (UltraGridColumn) parent.GetContext(typeof (UltraGridColumn)); var editor = new UltraTextEditor(); editor.Text = column.Header.Caption; var element = editor.UIElement; element.Rect = parent.Rect; parent.ChildElements.Clear(); parent.ChildElements.Add(element); } }
This still causes the texteditor to be disabled (can't get it in edit mode).
Or do you mean to just locate a texteditor over the headers without adding it to the ChildElements collection?
Isn't that very tricky (-> when resizing headers, I would have to manually sync the texteditor size...)
kevinmeiresonne said:This still causes the texteditor to be disabled (can't get it in edit mode).
My guess is that you have to add the TextEditorControl to the form, or even better, to the grid's Control's collection. That way it shows on top of the grid.
kevinmeiresonne said:Or do you mean to just locate a texteditor over the headers without adding it to the ChildElements collection?
Yes. You need not add any elements to anything. you just position a control over the column header. It's probably not a good idea to create a new UltraTextEditor inside the CreationFilter, though. Or at least create some kind of caching mechanism so you re-use the same one. Otherwise, you will end up creating an indefinite number of controls.
kevinmeiresonne said:Isn't that very tricky (-> when resizing headers, I would have to manually sync the texteditor size...)
Not at all. The creation filter will get called again, any time the header moves or resizes for any reason.