Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
660
UserControl as CellEditor - AutoSize doesn't work
posted

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
Parents Reply Children
No Data