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
Thanks! That solved it!
I had to tweak your code a bit. I don't want to enter edit mode every time. Just when I don't skip the cell so the final code that works is like this:
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++; } } else { EntryGrid.EnterEditMode(EntryGrid.ActiveCell); }
Thank you for your efforts on solving this!
I found a way that should work for your implementation.
1. Set IsOnCellActiveEditingEnabled to false, or just remove that line of code.
2. Use the snippet of code below.
void theGrid_ActiveCellChanged(object sender, EventArgs e) { int currindex = 0; RowBase row = theGrid.ActiveCell.Row; theGrid.EnterEditMode(theGrid.ActiveCell); 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; } } currindex++; } } }
The EnterEditMode method that gets called on the ActiveCell simulates the IsOnCellActiveEditingEnabled functionality you wanted to use, while allowing you to skip cells that are logically not editable.
Here's the sample project attached. You need to re-add your IG references there. I've used 10.3 versions so I don't know if this behavior is already fixed in 11.1?
Doesn't work. Maybe the cell is not in the edit mode just yet or something? The result is still that the cell which should be skipped is stealing back the active cell right after it's set to the next one. So it will be an endless loop and finally results in StackOverFlowException...
anttisimonen said: I think I've found what is breaking my project. I did a new sample project to see what breaks it and found out that setting IsOnCellActiveEditingEnabled to True, breaks your code. Without that it works fine. Can you try with IsOnCellActiveEditingEnabled=True and see if you can break your code? And of course if you can find a solution how to make it work with that too :) Thanks again!
I think I've found what is breaking my project. I did a new sample project to see what breaks it and found out that setting IsOnCellActiveEditingEnabled to True, breaks your code. Without that it works fine.
Can you try with IsOnCellActiveEditingEnabled=True and see if you can break your code? And of course if you can find a solution how to make it work with that too :) Thanks again!
That means your cell enters edit mode on each new cell activation. What we'd need to do is tell it to exit edit mode before the active cell change.
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) { EntryGrid.ExitEditMode(false); row.Cells[currIndex + 1].IsActive = true; row.Cells[currIndex + 1].IsSelected = true; return; } return; } currIndex++; } }
Let me know if that does the trick for you?