1

So I have a couple of lists inside a WPF ComboBox inside a datagrid (DataGridComboBoxColumn and DataGridTemplateColumn's with ComboBox). However when I change the selected item for a ComboBox, keep my mouse hovering over the list and then scroll, the selected Item changes. Because I have this inside a DataGrid (that can have a scrollbar, and because some lists have 4000+ items I want to avoid that this can happen for the end user however I can't seem to find how to disable this scrolling feature.
I've searched the corners of the Internet far and wide but I can't seem to come up with a proper solution for this problem.

This is my source code for one of the ComboBoxes:

<!--  Processed status  -->
<DataGridComboBoxColumn Header="Parsed Status"
    SelectedItemBinding="{Binding Status}"
    Width="auto">
    <DataGridComboBoxColumn.ElementStyle>
        <Style TargetType="{x:Type ComboBox}">
            <Setter Property="ItemsSource"
                Value="{Binding StatusList}" />
        </Style>
    </DataGridComboBoxColumn.ElementStyle>
    <DataGridComboBoxColumn.EditingElementStyle>
        <Style TargetType="{x:Type ComboBox}">
            <Setter Property="ItemsSource"
                Value="{Binding StatusList}" />
        </Style>
    </DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>

Now here's the kicker to the issue. The entire application is written in MVVM so the fix should be implemented entirely without code-behind. :)

Thank you for taking a look.
Kind regards.

Ben
  • 166
  • 2
  • 19
  • Any code behind can be refactored into behavior, so kicker is not an issue and shouldn't be a factor to limit the answers. Have you [been here](https://stackoverflow.com/q/2189053/1997232) or what have you tried? – Sinatr Mar 14 '18 at 10:01
  • Just a little side note. MVVM != No code behind at all. Since it's a purely a view related thing it doesn't make sense to put view logic in your viewmodel, and sometimes it's not worthy to put everything in xaml. I would consider the option to work with the DropDownClose event, and try to move the focus on the parent (i.e. the datagrid) – Daniele Sartori Mar 14 '18 at 10:01
  • Thanks for the feedback. I ended up adding an event on the loading of the combobox (because a routed event was needed) and adding to the DropDownClosed event to focus on the main window. Thank you all for your help! – Ben Mar 14 '18 at 12:58

1 Answers1

0

Try using a template column instead of the DataGridComboboxColumn like this:

<DataGridTemplateColumn Header="Parsed Status">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <ComboBox ItemsSource="{Binding StatusList}" DisplayMemberPath="DisplayProperty"
                                  SelectedValuePath="ValueProperty" SelectedItem="{Binding Status}"/>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

If you have multiple such columns, then define the DataTemplate in the window resources and resuse it for the columns based on it's key something like this:

<DataGridTemplateColumn Header="Parsed Status" CellTemplate="{StaticResource TemplateResourceKey}">
Raviraj Palvankar
  • 879
  • 1
  • 5
  • 9