Can anyone help me to set focus on allowed new row part of UltraWinGrid? Example is as follows:
After allowing ultrawingrid to add new row with the following code:
UltraGrid.DisplayLayout.Override.AllowAddNew =
AllowAddNew.FixedAddRowOnBottom;
I want to set focus on the following part (selected in blue):
1
ABC
2
DEF
*
As I want the following functionality:
1. When the grid is loaded the focus should be on the selected blue cell.
2. When the user keys any value in blue cell and tabs or hits enter the row should be added to the grid (without description (eg. ABC, DEF)).
3. Reposition the cursor focus to the blue cell.
#1 and #3 seem to be the same thing.
The tricky part of this is that you cannot set focus inside Form_Load. So you either have to use some other event that fires after the grid has painted once, or else use a BeginInvoke to create a delay.
So you could create a method like this:
private void FocusAddNewRow() { this.ultraGrid1.Rows.TemplateAddRow.Activate(); this.ultraGrid1.ActiveRow.Cells[0].Activate(); this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false, false); }
And then call it with a BeginInvoke:
this.BeginInvoke(new MethodInvoker(this.FocusAddNewRow));
I'm not sure I understand what you mean by #2. If the user types into the row, it will be added to the grid. If they do not make any changes, you want to commit a blank row? If that's the case, then you need to set this.ultraGrid1.Rows.AddRowModifiedByUser = true so the grid thing the user has made a change.
It works.
Thank you very much for your help Mike.