Hi,
i have another one before the weekend ;)
I've put my own UserControl as Editor into a Cell with the help of UltraControlContainerEditor. This works technically - but:
I need the editor to be wider than the Column (for the user to see the complete UserControl) - AutoSize for the Cell doesn't work in this case.
I found out, that AutoSize won't work WITHOUT UserControl too if you set a Column to DateTime-Format (in this case you will see the DateTime-Picker as Editor but try to make the Column really small - you won't be able to pick date then, even with AutoSize set to true)
So here is what i've tried:
- Put an UltraGrid on a form and connect it to a Datasource with some Columns. One of those is a DateTime-Column named "Datum"
- Create an UserControl. In the Designer just make it wide, say about 400 pixels. Put two or three edit-fields next to each other on this control (i've put a Date and a Time Component on it). I named that class "ucDateTime" (That class needs a Value-Property and a ValueChanged Event of course.
- Prepare this UserControl as Cell-Editor like this:
private UltraControlContainerEditor _contEditorDT;
...
_contEditorDT = new UltraControlContainerEditor(); _contEditorDT.EditingControl = new ucDateTime(); _contEditorDT.EditingControlPropertyName = "Value"; this.dfgrid1.DisplayLayout.Bands[0].Columns["Datum"].EditorComponent = _contEditorDT; this.dfgrid1.DisplayLayout.Bands[0].Columns["Datum"].AutoSizeEdit = DefaultableBoolean.True;
Now select that "Datum"-Cell and open the editor. You will see the UserControl but not completely, it's cut off - No AutoSize working.
Then i tried this:
this.dfgrid1.BeforeAutoSizeEdit += dfgrid1_BeforeAutoSizeEdit;
void dfgrid1_BeforeAutoSizeEdit(object sender, CancelableAutoSizeEditEventArgs e) { UltraGrid grid = sender as UltraGrid; if (grid == null) return;
if (grid.ActiveCell == null) return;
if (grid.ActiveCell.Column.Key == "Datum") { if (grid.ActiveCell.Column.Width < 200) e.StartWidth = 200; if (grid.ActiveCell.Column.CellMultiLine == DefaultableBoolean.True && grid.ActiveCell.Row.Height < 100) e.StartHeight = 100; // Set the max width and height. The UltraGrid will not resize the edit control // larger than max height and max width. e.MaxHeight = 400; e.MaxWidth = 400; // One can cancel auto-size-edit in which case the cell will do regular editing. bool cancelAutoSizeEdit = false; if (cancelAutoSizeEdit) e.Cancel = true; }
}
The program runs thru that code, i can see in the debugger that my size is set - but it doesn't help - the Cell-Editor still is the width of the column.
Why? And how can i solve that? (did i found another flaw? hopefully i'm missing a hidden property or something :))
(Attached is a picture of my testing-App. You see the simple UserControl in the Designer on the top. Below is the running application where you can see, that the editor really is my userControl but is only the width of the column - AutoSize doesn't work even if forced via the Event as described above)
Thanks
AutoSizeEdit is intended for use with long text fields. Since a DateTime is unlikely to ever be long enough to warrant the need for it, it's not supported on DateTime field (or any masked field, in fact). It's actually a function of the editor, so it's only support for UltraTextEditor and other text-based editors.
In theory, I suppose it could be make to work for UltraControlContainerEditor, but it is currently not supported. Please Submit a Feature Request and perhaps this can be added in a future release.
BTW, the way the grid determines the appropriate size when using UltraControlContainerEditor is via the GetPreferredSize method on the control, not the Size property. So if you override GetPreferredSize on your control, then the grid column would AutoSize using that size whenever you autosized the column or row.
OK, so AutoSizeEdit won't solve that problem here.
I've tried to override PreferredSize for my userControl but it's never called (maybe because it's only the editor - not the renderer?)
Anyway - I'm still looking for a solution to:
- let the user enter a Date and optionally a time (preferabely in one cell)
- without having to have the cell at an enormous width all the time.
Using a UserControl with two Controls on it works - but how can i make sure that the user can see the whole control even if the cell is smaller?
Do you have any other ideas? Is it possible to have a UserControl "Pop up" (or Pop over if you will) from the cell and be bigger than the cell itself?
Hello,
Thank you. I am glad we were able to direct you to a solution. Let us know if you have any additional quesitons regarding this matter. Have a nice day.
Hey,
i marked this as solution.
I use the Popup.Closed Event to do a grid.PerformAction(ExitEditMode).
Now: If i Enter the EditMode of the cell i show the popup and set the focus. If i switch away with Tab i close the popup on jump to the prev/next cell. And if user clicks with mouse somewhere else (so that the popup closes) i exit the edit mode of the cell so that the default-editor isn't visible.
Last "Problem" is: Because it's a DateTime-Cell, the DropDown-Button for the Calendar is visible on that cell. But i'm sure there is another property for that somewhere :)
I'm currently experimenting with that.
I cannot use CellActivate / CellDeactivate because i like to set the focus on that PopupControl for the user to quickly edit. So i have used OnEnterEditMode and OnExitEnterMode which looks promising.
Also i have added two events to the UserControl (the PopupControl): OnExitNext and OnExitPrev (if the user tabs out of the last or shift-tabs out of the first control). This way i can do a PerfomAction with: ExitEditor + Next/Prev Cell + EnterEditor. This way i'm able to Enter the Edit Mode of a cell, tab thru the cells (even thru the popup control)
Only problem so far: Sometimes, if i play with mouse-clicks, i am able to close the Popup but having the default cell-editor (it's a DateTime field) opened. Because i have my own (popup) editor, i don't like that. The user should always see the Popup on this cell if the editor is activated - never the default-editor...
If i know a reproducable way to see that problem, i will offer an short example code. Maybe i can find a solution. will see tomorrow
I like your pop up idea. You can use our UltraPopupControlContainer and show your entire user control over the cells when they're clicked.
I attached a sample the demonstrates this. Let me know if you have any questions regarding this matter.