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
Hi Boris,
Thank you for posting in our forums.
What you could do in order to right align the editor is to use the CreationFilter interface. You can use this interface, in order to modify the UIElements of the grid. For more information, please visit this link:
http://help.infragistics.com/Help/Doc/WinForms/2012.2/CLR4.0/HTML/Win_Creation_Filter.html
In the interface set location of the editor that is displayed and its EditorWithTextUIElement. This will display the editor in the correct place and it will prevent it from moving while typing.
I have attached a sample which demonstrates this approach.
Please let me know if you have any additional questions.
Hm, first: Thank you for that approach. It looks like it could work
But there are a lot of new problems i have with this one:
- If you start typing in the multiline-editor, all other values (in other cells) disappear.
- Together with the "BeforeAutoSizeEdit"-Function "everything" messes up ....
....try my attached example. Make the Form a bit smaller, so that the last column is smaller than 400 pixels. Then enter a new line.
See: If you type in the notes-cell, the values of the other cells disappear; if you press Tab on the notes-cell the new row is added but not displayed - only the notes-data is displayed but completely out of place.
If you detach the BeforeAutoSizeEdit it works better - but then again the editor will never be wider than the column.