Search code examples
wpfxamldatagridwpfdatagrid

SelectedIndex in DataGrid. Value -1 during scrolling


I have a dataGrid with a scroll.

Grid is thrown into a StackPanel of such height that 6 lines from DataGrid are visible.

Each row has a ComboBox with different number of items. If there are more lines in dataGrid than 8 then when using the scroll, when the mouse is above the DataGrid, SelectedIndex changes to -1. This happens randomly for different ComboBox positions.

The situation only occurs when there are more than 8 rows.

I can block as below descending below 0 but this is not a disconnect. This causes other problems.

public int SelectedIndex
        {
            get { return _SelectedIndex; }
            set
            {
                _SelectedIndex = (value >= 0) ? value : 0;
                Console.WriteLine("SelectedIdx: " + value);
                //_SelectedIndex = value;
                OnPropertyChanged("");
            }
        }

Can anyone with a similar problem meet?


Solution

  • Problem:

    • Panel virtualization

    Solution:

    • <DataGrid VirtualizingPanel.IsVirtualizing="False">