I have a DataGrid with a ComboBox in a DataTemplate
<DataGridTemplateColumn Header="Stock Name" Width="290">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding StockName}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox Width="290" Name="cmbStock" ItemsSource="{Binding Path=Stocks}" FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}" ></ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
I want the ComboBox to DropDownOpen when i reach this DataGridCell using Tab
This include in making the DataGrid Cell in edit mode when i reach it.
I am using WPF MVVM
I think what you need to do is to force the data grid into “single-click or tab” edit mode. Basically when the cell is focused force the grid to swtich the CellTemplate to CellEditingTemplate. The code for that is:
Now how and where you hook that up depends on how much work you want to do. You could extend the DataGrid class and introduce DependencyProperty “SingleClickEdit” or whatever you wanna call it. Then when monitor/preview key down and on tab select the cell and force it to be in edit mode. Or if you need it just for that column, you could just monitor:
Then in .cs code, in OnGotFocus() for example, call datagrid.BeginEdit().
EDIT:(per comments/converation below)
add IsDropDownOpen = true to your combobox
in .cs
That should do it, work in my test :), basically you’re forcing the datagrid into edit mode on selection, and in your edit mode, you got the combobox that is already open