I am using WPFToolKit DataGrid to display data; In my use case
- user clicks on a cell and enters a value (I trap the event and set the focus to the
TextBox) - Presses Enter
- Value is committed
- Focus shifts to Next Cell
Now, user can't enter any value in the TextBox(in the DataGridCell) unless he clicks on the cell. The TextBox can be a part of various controls(like NumericUpDown, Calendar etc.).
This behavior is similar to Excel but I am not able to shift the focus to the Underlying TextBox as various other wrapper user controls are there in the DataGridCell(something like DataGridCell contains MatrixCellContainer, which contains MatrixCell, which contains UpDown Control)
Any pointer will be really helpful.
Update:
I can achieve what I am looking for by handling DataGridCell_Selected event like this :
private void DataGridCell_Selected(object sender, RoutedEventArgs e)
{
Microsoft.Windows.Controls.DataGridCell dataGridCell =
sender as Microsoft.Windows.Controls.DataGridCell;
// ToDo: This is a very bad hack;
// should be replaced by some proper technique
if (dataGridCell != null)
{
NumericUpDownBase<int>[] IntUpDownControls =
dataGridCell.GetChildrenOfType<NumericUpDownBase<int>>();
if (IntUpDownControls.Count() != 0)
{
IntUpDownControls[0].Focus();
//Keyboard.Focus(IntUpDownControls[0]);
}
else
{
NumericUpDownBase<double>[] DblUpDownControls =
dataGridCell.GetChildrenOfType<NumericUpDownBase<Double>>();
if (DblUpDownControls.Count() != 0)
{
DblUpDownControls[0].Focus();
//Keyboard.Focus(DblUpDownControls[0]);
}
}
}
}
But I know there will be a better way to achieve this!
Finally I settled with this -
Still looking for a better approach though...