Hi,
I have a grid with AllowAddNew set to TemplateOnBottom, CellClickAction set to CellSelect, SelectTypeCell set to single (all other Select Types set to None) and most importantly TabNavigation set to NextControl. The grid starts of empty apart from the Add New row.
The first problem was that when you tab to the grid initially there's no active cell and you don't appear to be able to do anything.
My workaround for that was to call Rows.TemplateAddRow.Activate and Rows.TemplateAddRow.Cells(0).Activate after the form has loaded.
The next problem is that when you press tab the active/selected cell outlines disappear and it takes multiple tab presses to get to the next control (number of extra tab pressed equals number of columns in the grid). When you tab back you have the original problem again of no active cell.
If you add a row and have a cell seelcted on the active row then it works fine and you can tab back and forth without losing the active cell.
So what I need is a way of ensuring that I can always use keyboard entry when there's an Add New row present and for the tab behaviour to match the rest of the grid (i.e. just tab to the next control).
Thanks,
John.
Yep, that sorted it.
Hi John,
I usually do something like this to ensure there is always an active cell whenever the grid has focus.
private void ultraGrid1_Enter(object sender, EventArgs e) { UltraGrid grid = ((UltraGrid)sender); grid.BeginInvoke(new MethodInvoker(this.EnsureActiveCell)); } private void EnsureActiveCell() { if (this.ultraGrid1.ActiveCell == null) { this.ultraGrid1.Rows.TemplateAddRow.Cells[0].Activate(); //this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false, false); } }
The PerformAction I added here is optional, in case you want the cell to be in edit mode. I have also attached a small sample project demonstrating this code in action.