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,
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.
I am just checking, if you need any further assistance on this matter.
Thank you for your feedback. I have been looking into your scenario and in order to skip the tabbing through the other controls in the window you need to handle the ‘KeyDown’ event when tabbing out from the last cell of the XamDataGrid like:
private void XamDataGrid1_PreviewKeyDown(object sender, KeyEventArgs e)
{
XamDataGrid grid = (XamDataGrid)sender;
int postion = grid.ActiveCell.Field.ActualPosition.Column;
if (e.Key == Key.Tab || e.Key == Key.Enter)
if (grid.ActiveCell.Record.Index == grid.Records.Count - 1 && grid.ActiveCell.Field.ActualPosition.Column == grid.FieldLayouts[0].Fields.Count - 1)
e.Handled = true;
grid.ExecuteCommand(DataPresenterCommands.CellFirstOverall);
grid.ExecuteCommand(DataPresenterCommands.StartEditMode);
}
I am attaching a modified version of your sample application(datagridfieldsettings_modified.zip) with this modification.
Let me know, if you need any further assistance on this matter.
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!