Setting focus on DataGrid cell

Nov 3, 2010 at 8:06 PM

I'm using a DataGridTemplateColumn with Textbox and I'm trying to set the focus from the code, but i couldn't get it to focus.  I'm putting this code in dg_SelectionChanged event. 

I've tried many way including:

DataGridRow dgr = (DataGridRow)dg.ItemContainerGenerator.ContainerFromItem(dg.SelectedItem);
dgr.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));


dg.CurrentCell = new DataGridCellInfo(dg.SelectedItem, dg.Columns[1]);

Please advice.