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
Multiline-Cell - Dropdown-Editor resized via code - how to align it to be always completely visible?
posted

Hi again,

say you have an UltraGrid and a Datasource with some columns. The last column is a "notes"-column. It should be multiline and the editor for that cell should have a size that is independend from the column width, so that the user can always enter easily without resizing the grid first.

This is possible via the "BeforeAutoSizeEdit"-Event.

problem is: The resized editor (wider than the cell) is:

- not right aligned with the cell if the wider editor won't fit inside the grid

- and not above the grid, so that it could grow over it and beyond the form if needed

If you also set the autosize option to resize-last-column, you will run into this problem very often (when having small dialogs with grids)

You can reproduce that:

- Put an UltraGrid on a Form

- with a DataSource having 4 or 5 columns. The last on is the notes column.

Init it like this:

this.grid1.BeforeAutoSizeEdit += grid1_BeforeAutoSizeEdit;
this.grid1.DisplayLayout.Bands[0].Columns["Notes"].AutoSizeEdit = DefaultableBoolean.True;
this.grid1.DisplayLayout.Bands[0].Columns["Notes"].CellMultiLine = DefaultableBoolean.True;
this.grid1.DisplayLayout.AutoFitStyle = AutoFitStyle.ExtendLastColumn; //optional

and of course the BeforeAutoSizeEdit function:

        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.Width < 400)
                e.StartWidth = 400;
 
 
 
            if (grid.ActiveCell.Column.CellMultiLine == DefaultableBoolean.True &&
                grid.ActiveCell.Row.Height < 100)
                e.StartHeight = 100;
 
            e.MaxHeight = 400;
            e.MaxWidth = 400;
 
            bool cancelAutoSizeEdit = false;
            if (cancelAutoSizeEdit)
                e.Cancel = true;
        }

I've attached a screenshot for better understanding.

Question is:
- is there a way to make that dropdown-Editor right-aligned if it doesn't fit inside the grid?
- or is there way to make it stay above the grid, so that it could grow beyong it?
- or is there a clever work-around using some other kind of editor that would do the trick? The goal is, to let the user easily enter multiline notes in a rather small column.

Thanks a lot
Boris