We have a solution where we need be able to only tab between editable cells in a grid. The default behavior of the tab is to select the next cell in the grid. Is there any way to override this, so that clicking tab the grid will select the next editable cell in the grid?
Regards
Bjarne
Here's one way to achieve the skipping of cells. It uses the ActiveCellChanged event of the XamGrid. Some further work could be done to improve it.
void theGrid_ActiveCellChanged(object sender, EventArgs e) { int currindex = 0; if (YOUR LOGIC HERE COMPARING IF THE CELL SHOULD BE SKIPPED) { foreach (Infragistics.Controls.Grids.Cell cell in theGrid.ActiveCell.Row.Cells) { if (cell.IsActive) { if ((theGrid.Rows[theGrid.ActiveCell.Row.Index].Cells.Count - 1) > currindex) { theGrid.Rows[theGrid.ActiveCell.Row.Index].Cells[currindex + 1].IsActive = true; theGrid.Rows[theGrid.ActiveCell.Row.Index].Cells[currindex + 1].IsSelected = true; return; } else { if ((theGrid.Rows.Count - 1) >= theGrid.ActiveCell.Row.Index) return; theGrid.Rows[theGrid.ActiveCell.Row.Index + 1].Cells[0].IsActive = true; theGrid.Rows[theGrid.ActiveCell.Row.Index].Cells[currindex + 1].IsSelected = true; return; } } currindex++; } } }
Thanks for the code, but I don't get it to work. I have slightly different scenario because I have grouped grid but I think it should work with this kind of code. I have simplified it a bit.
RowBase row = EntryGrid.ActiveCell.Row; int currIndex = 0; if (IS TO BE SKIPPED) { foreach (Cell cell in row.Cells) { if (cell.IsActive) { if ((row.Cells.Count - 1) > currIndex) { row.Cells[currIndex + 1].IsActive = true; row.Cells[currIndex + 1].IsSelected = true; return; } return; } currIndex++; } }
The problem is that after I've changed the IsActive to true for the next cell, something changes it back to the previous. My callstack just says it's external code before coming again to ActiveCellChanged (of course it comes there once after the first change). I've removed all the other code related to my Grid to eliminate other causes for this kind of behaviour. Should the IsActive be set to False first before setting it to true for other column? Any other ideas?
I also tried it so that I first set the IsActive/IsSelected to false for the "to-be-skipped" cell and then set the new active cell when it comes back to ActiveCellChanged event. That didn't work either. Something is still changing it eventually back to the previous one. Any ideas?
More information. It seems that the "old" cell still remains in edit mode, even if I move the IsActive and IsSelected to another cell? That's probably the reason the grid changes the IsActive back to the old value over and over again.