This project is read-only.
2

Resolved

DataGrid SelectionChanged event fired many times when scrolling

description

If you scroll up/down with the mouse and you don't change the selected row(s) but the event will be fired as many times as many row you scrolled. In this case the event should not be fired.
If you scroll with keyboard and you use the page up/down keys, you jump a few rows and change the selection. In this case the event will be fire not only once but as many times as many rows you jumped.
 
This behaviour is a major performance issue if you have a longer task to do when you have the selection changed.
 
To reproduce:
1, Create a DataGrid
2, Fill it with 100 rows
3, Make the DataGrid big enough to display 20 lines
4, Make the Vertical Scrollbar visible
5, Create a SelectionChanged event (you can put a Sleep() into the handler to feel the problem:)
6, Put a breakpoint into the event
7, Run the app
8, Select a row
9, Scroll with keyboard or mouse
 
 
I used the DataGrid of the June 2009 Toolkit, and also tried the DataGrid in build 29533 (November 2009).

file attachments

comments

navin08 wrote Dec 16, 2009 at 2:00 AM

andrasfuchs ,

I could not repro this issue. Can you please provide a simple isolated repro application?

Navin

andrasfuchs wrote Dec 16, 2009 at 1:10 PM

Hello Navin,

I created a repro project, so you can see the problem. I have to admit, that my description was not precise enough, but I realized it only when I started to build this repro project.
So the problem is not with the DataGrid itself, but with the DataGridComboBoxColumn. The DataGrid works perfectly until I added the DataGridComboBoxColumn and set its properties.
I've tested it with the wpf toolkit b29533 so the DataGrid reference in the project points to a local project, you might need to replace it to make it work.
Please find it attached.

Andras

wrote Dec 16, 2009 at 1:10 PM

wrote Dec 16, 2009 at 1:11 PM

navin08 wrote Dec 17, 2009 at 1:39 AM

Hello Andras,

I was able to repro the issue using your project. The issue here is that on scrolling, DataGridComboBoxColumn fires the SelectionChangedEvent and not the DataGrid. But SelectionChangedEvent is a routedevent which if unhandled bubles up and eventually gets handled by the DataGrid SelectionChangedEventHandler. Therefore it is the responsibility of the DataGrid Event Handler to see if the event is fired from some inner control (ComboBox in this case) or by the DataGrid itself. The code for example would look like:

private void orderDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        // put a breakpoint here            
        if (e.OriginalSource == this.orderDataGrid)
        {
             //Your code for the handler                
        }            
    }
Hope this helps.

Navin

andrasfuchs wrote Dec 17, 2009 at 11:44 AM

Hello Navin,

Excellent, thank you for your help!

Andras

wrote Dec 18, 2009 at 1:07 AM

wrote Feb 22, 2013 at 2:40 AM

wrote May 16, 2013 at 1:31 PM

wrote May 16, 2013 at 1:31 PM

wrote Jun 14, 2013 at 8:35 AM

geardoom3 wrote Mar 13, 2015 at 1:26 AM

Image

wrote Mar 13, 2015 at 1:27 AM

geardoom3 wrote Mar 13, 2015 at 1:27 AM

Hmm this place doesn't like OneDrive link. Here's the image again as attachment

geardoom3 wrote Mar 13, 2015 at 1:29 AM

Hmmm 2 I don't see any attachment to my text above. Let's try the OneDrive link directly in text. Sorry about that

http://1drv.ms/1x0gTi2