Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
450
Check if the currently selected cell is the very last in the grid
posted

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.

private void DataGrid_OnPreviewKeyDown(object sender, KeyEventArgs e)
{
    XamDataGrid grid = (XamDataGrid) sender;
    if (e.Key == Key.Tab || e.Key == Key.Enter)
    {
       if(grid.ActiveCell == ((DataRecord)grid.Records[grid.Records.Count-1]).Last())
        {
           grid.ExecuteCommand(DataPresenterCommands.CellFirstOverall);
         }
     }
 }

Is there maybe any "better" way to do this?