3

I have an application that uses a WPF DataGrid that has thousands of rows. I was having performance issues with scrolling using the Vertical ScrollBar so I did some research and found out I can defer the loading of the rows until I finish scrolling by setting ScrollViewer.IsDeferredScrollingEnabled = "True" in the DataGrid. Everything worked fine until some users noticed that scrolling through a list of options in a DataGridComboBoxColumn inside the DataGrid now scrolls the whole DataGrid instead of the ComboBox. This occurs only when you mouse drag on the ComboBox scrollbar but not when scrolling with a mouse wheel.

I put together a example class in vb using .net 4.0 that will illustrate the issue when the ComboBox in the Column is scrolled through using a mouse drag.

XAML

<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="279" Width="496">
<Grid>
    <DataGrid AutoGenerateColumns="False" Height="209" HorizontalAlignment="Left" Margin="12,12,0,0" Name="DataGrid1" VerticalAlignment="Top" Width="448" ItemsSource="{Binding}" ScrollViewer.IsDeferredScrollingEnabled="True">
        <DataGrid.Columns>
            <DataGridTextColumn Binding="{Binding Path=Name}" Header="Name" />
            <DataGridComboBoxColumn Header="Drag Scroll through Items in a cell below" x:Name="IssueComboBoxColumn" />
        </DataGrid.Columns>
    </DataGrid>
</Grid>

CODE

Class MainWindow 

Public Sub New()

    ' This call is required by the designer.
    InitializeComponent()

    ' Add any initialization after the InitializeComponent() call.
    Dim sourceList As New List(Of itemExample)
    For i As Integer = 0 To 50
        sourceList.Add(New itemExample("Item" & i.ToString, 4))
    Next

    Dim comboList As New List(Of String)
    For i As Integer = 0 To 50
        comboList.Add("Drop Item " & i.ToString)
    Next

    DataGrid1.DataContext = sourceList
    IssueComboBoxColumn.ItemsSource = comboList
    IssueComboBoxColumn.SelectedValuePath = "ComboItem"
End Sub

Private Class itemExample
    Property Name As String
    Property ComboItem As Integer


    Public Sub New(name As String, comboItem As Integer)
        Me.Name = name
        Me.ComboItem = comboItem
    End Sub
End Class
End Class
Community
  • 1
  • 1
Net Dev
  • 416
  • 4
  • 21

0 Answers0