I'm trying to retrieve the datagrid because I want to focus on a specific cell in a row. I have a DataGridRow based on the LoadingRow event that I use by doing this:
<i:EventTrigger EventName="LoadingRow">
<utils:InteractiveCommand Command="{Binding RelativeSource = {RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.MainWindowViewModel.SDataGrid_LoadingRow}"/>
</i:EventTrigger>
But in the function receiving this, I only am able to get the DataGridRow.
public void SDataGridLoadingRow(object param)
{
DataGridRowEventArgs e = param as DataGridRowEventArgs;
e.Row.Tag = e.Row.GetIndex().ToString();
}
I want to get a specific cell from the row and focus on it so the user can type. Is this possible?
I'm using MVVM
Also have this now
public void SDataGridLoadingRow(object sender, DataGridRowEventArgs e)
{
e.Row.Tag = e.Row.GetIndex().ToString();
DataGrid dataGrid = sender as DataGrid;
dataGrid.Focus();
// Cancel our focus from the current cell of the datagrid
// if there is a current cell
if (dataGrid.CurrentCell != null)
{
var cancelEdit = new System.Action(() =>
{
dataGrid.CancelEdit();
});
Application.Current.Dispatcher.BeginInvoke(cancelEdit,
System.Windows.Threading.DispatcherPriority.ApplicationIdle, null);
}
dataGrid.CurrentCell = new DataGridCellInfo(
dataGrid.Items[e.Row.GetIndex()], dataGrid.Columns[1]);
var startEdit = new System.Action(() =>
{
dataGrid.BeginEdit();
});
Application.Current.Dispatcher.BeginInvoke(startEdit,
System.Windows.Threading.DispatcherPriority.ApplicationIdle, null);
}
And the previous row is still in edit mode... can't quite figure out how to get it out of edit mode...