locked
Proper Tab Order of Controls Embedded within a SL DataGrid RRS feed

  • Question

  • Ok so I have a standard SL DataGrid using Embedded controls within CellTemplate's to provide functionality for say example, deleting rows or navigating to other screens etc.

    The default allows the Tab order to set focus to the controls in the first row of the DataGrid and will tab through the first Row fine. However where one would expect the Tab order to jump to the next row, it instead moves to the next control outside of the Grid. Any ideas how I can set the Tab order to respect the embedded controls within each Row so the user can Tab fluidly through the elements of each Row created in the DataGrid?

    I see what's listed here for the Default Keyboard behavior but I couldn't identify a solution from it. Any insight to be shared? Thanks for looking!


    Please mark answers as helpful when used, and answered when completed.

    Monday, March 5, 2012 7:53 PM

All replies

  • Hey KS.

    "If the current cell is not in edit mode, moves the focus to the next control in the tab order of the parent container."

    Basically you have to put your DataGrid into edit mode or else you are fighting with the Browser over who has control of the tab key behavior. 

    I put this on the dataGrid ...

    KeyDown="handleTabKey"

    		private void handleTabKey(object sender, System.Windows.Input.KeyEventArgs e)
    		{
    			if ((e.Key == Key.Tab) && (Keyboard.Modifiers == ModifierKeys.None))
    			{
    				dataGrid.BeginEdit();
    				e.Handled = true;
    			}
    			else if ((e.Key == Key.Tab) && (Keyboard.Modifiers == ModifierKeys.Shift))
    			{
    				dataGrid.BeginEdit();
    				e.Handled = true;
    			}
    		}

    Another option would be to cylce through the rows when Tab is pressed...

    		private void handleTabKey(object sender, System.Windows.Input.KeyEventArgs e)
    		{
    			if ((e.Key == Key.Tab) && (Keyboard.Modifiers == ModifierKeys.None))
    			{
    				dataGrid.SelectedIndex = dataGrid.SelectedIndex + 1;
    				e.Handled = true;
    			}
    			else if ((e.Key == Key.Tab) && (Keyboard.Modifiers == ModifierKeys.Shift))
    			{
    				dataGrid.SelectedIndex = dataGrid.SelectedIndex - 1;
    				e.Handled = true;
    			}
    		}

    This post is a discussion of others who have your same issue... http://forums.silverlight.net/p/28726/99886.aspx

    Hope that gives you some ideas.

    ~Christine


    Tuesday, March 6, 2012 3:45 AM
  • Thanks Christine, I don't know where you find the time! I'll have to give this a shot a bit later, thank you again :)

    Please mark answers as helpful when used, and answered when completed.

    Tuesday, March 6, 2012 2:57 PM