Hi guys!
I came out with some code for achieving the title of this post, but I'm not really satisfied with how it looks. I'm pretty sure there's a better way of doing it.
Imagine you have the simplest grid possible. All you want to do is give the ability to the user to add multiple rows just by pressing Enter. The user clicks on the AddRow, enter some text and hit Enter, the focus should still be at the AddRow so the user can continuously enter new rows. How would you do that?
What I did is I subscribed to the KeyDown event and on enter I run:
this.PerformAction(UltraGridAction.AboveCell, false, false);
this.PerformAction(UltraGridAction.BelowCell, false, false);
Hi,
Okay, I tried this out and I do see that the focus moves to the first cell in the new TemplateAddRow. But it does enter edit mode for me. Maybe your first cell is read-only and so that's why it does not enter edit mode on yours.
Anyway, what you can do is use the BeforePerformAction event to cancel the default behavior of the CommitRow action and handle it yourself. Like so:
private void ultraGrid1_BeforePerformAction(object sender, BeforeUltraGridPerformActionEventArgs e) { UltraGrid grid = (UltraGrid)sender; if (e.UltraGridAction == UltraGridAction.CommitRow) { e.Cancel = true; UltraGridRow activeRow = grid.ActiveRow; if (activeRow != null && activeRow.IsAddRow) { UltraGridCell activeCell = grid.ActiveCell; activeRow.Update(); if (activeCell != null) { grid.Rows.TemplateAddRow.Cells[activeCell.Column].Activate(); } grid.PerformAction(UltraGridAction.EnterEditMode); } } }
Thanks for the quick answer...
The issue is when I do that, the focus goes to the first column and it's not on edit mode. I'd need the focus to stay on the same column, and on editmode. So the user could do
Red[ENTER]
Blue[ENTER]
Green[ENTER]
Thanks again!
Have you tried setting AllowAddNew to one of the "Fixed" settings like FixedAddRowOnBottom or FixedAddRowOnTop?