SelectionChanged event fires a lot of times while scrolling

Nov 10, 2008 at 4:38 PM


When creating a column at runtime the SelectionChanged event fires a lot of times while scrolling.
When comment out the following lines it is working normal again.
The same happens when creating CheckBoxes.

dgcbc = new DataGridComboBoxColumn ();
dgcbc.Header =
dgcbc.MinWidth = 100;
dgcbc.ItemsSource = this.m_Priorities;
b =
new Binding ("collection");
b.Mode =
dgcbc.SelectedItemBinding = b;
dg.Columns.Add (dgcbc);

Thanks in advance fo your help.


Nov 10, 2008 at 5:14 PM
Do you mean SelectionChanged event on ComboBox???  If yes then that is by side effect of UI virtualization. When virtualization is enabled, as you scroll up and down the UI element of row along with its contents (which includes your combobox of the cells of combobox column) gets recycled and used for other row items. In the process the corresponding comboboxes are cleared of their selections and new selections are made based on the values on new row item. Hence resulting in SelectionChanged event. Your event handlers should be smart enough or re-entrant to handle this case.
Nov 10, 2008 at 5:32 PM
Thanks for your quick reply.
The SelectionChanged event of the dataGrid fires.
I understand what you are saying.
I just tested that the number of executing the event handler depends on the items in the combobox.
So how to disable UI virtualization of the datagrid or combobox?
Currently I dont understand what UI virtualization means.

I think it is better to use RowClick event if available. Is it available???
Or what is the smartest solution?

Thanks in advance fo your help.