Hello,
I'd like to check whether the user has currently the last (= most bottom right) cell in the grid selected, so I can jump back the the first cell in the grid if he tabs further.
I'm currently doing it like this. However this doesn't work if the user has altered the order of the columns and moved them around, since the last cell seems to always stay the same, even if it has been moved.
Is there maybe any "better" way to do this?
Hi,
I have been looking into your question and the issue in your scenario is that the field index is not changed when the field position is changed. In order to able to check the actual field position of the active cell you could you the following ‘if’ statement:
if (grid.ActiveCell.Record.Index == grid.Records.Count - 1 && grid.ActiveCell.Field.ActualPosition.Column == grid.FieldLayouts[0].Fields.Count - 1)
I am attaching a sample application(datagridActiveCellNavigation.zip) that shows my suggestion.
Let me know, if you need any further assistance on this matter.
Thanks, that worked well. I just had to additionally subtract the number of non-visible fields from the Fields.Count.
The only issue that I have now is that grid.ExecuteCommand(DataPresenterCommands.CellFirstOverall); doesn't go into the first cell, first row but in the second cell, first row. It works in your sample, but I'm a little stumped why it doesn't work in our application. I already removed all other events from the XamDataGrid we had, to rule out any side effects. The same happens if I use CellFirstInRecord, where it jumps to the second column in the current record. Do you maybe have an idea?
Thank you for your reply. In order to enter the first cell in edit mode I access its editor and invoke its ‘StartEditMode’ method:
CellValuePresenter.FromCell(grid.ActiveCell).Editor.StartEditMode();
You could see it in my sample application. Regarding your second concern if the focus is on the XamDataGrid when tabbing through the cell the tabbing does not goes out of the grid. If the focus is on element out of the XamDataGrid the tabbing goes through all other controls and then returns again to the XamDataGrid. This is the expected behavior.
I think you confused two different threads there :)
Thank you for your reply. I edited my previous post.
We found out what the issue was. Our last field in the grid used a template that modified the CellValuePresenter style. If we removed that, it worked. We first used a workaround that involved a hacky Thread.Sleep() call which made the whole stuff work:
grid.ExecuteCommand(DataPresenterCommands.CellFirstOverall);Task.Factory.StartNew(() =>
{ Thread.Sleep(50); }).ContinueWith((prevTask) => { if (grid.ActiveCell.IsActive) { CellValuePresenter.FromCell(grid.ActiveCell).Editor.StartEditMode(); } }, TaskScheduler.FromCurrentSynchronizationContext());
I've attached a slightly modified version of you sample that reproduces the issue, maybe you can tell what's going wrong there.
Thanks for your help!
I am just checking, if you need any further assistance on this matter.
Thank you for your reply. Let me know, if you need any further assistance on this matter.
Thanks, the missing e.Handled = true; seemed to be the final culprit.