Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SelectableFilterCollection SelectRow() fails on sorted/filtered collection #2676

Closed
desmetdirk opened this issue Aug 19, 2024 · 1 comment · Fixed by #2715
Closed

SelectableFilterCollection SelectRow() fails on sorted/filtered collection #2676

desmetdirk opened this issue Aug 19, 2024 · 1 comment · Fixed by #2715
Labels
Milestone

Comments

@desmetdirk
Copy link

Expected Behavior

Calling SelectRow(rownr) should select the correct row in the GridView on filtered or sorted views

Actual Behavior

The wrong row gets selected.

Steps to Reproduce the Problem

  1. see C# code below

Code that Demonstrates the Problem

var grid = new GridView<MyClass>();
.....
var collection = new SelectableFilterCollection<MyClass>(grid, somelist) {};
grid.DataStore = collection;
collection.Sort = coll.Sort = (e1, e2) => e1.Name.CompareTo(e2.Name);
....
coll.SelectRow(5);

Proposed fix

The problem seems to be in the Rebuild method, that gets viewToModel wrong. Can be fixed by adding 1 line, see below

        protected override void Rebuild()
        {
            base.Rebuild();
            if (base.HasFilterOrSort)
            {
                viewToModel = new Dictionary<T, int>(base.Count);
                for (int i = 0; i < base.Count; i++)
                {
                    viewToModel.Add(this[i], i);
                }

                modelToView = new Dictionary<int, int>(base.Count);
                for (int j = 0; j < base.Items.Count; j++)
                {
                    if (viewToModel.TryGetValue(base.Items[j], out var value))
                    {
                        modelToView.Add(j, value);
                        // -------->  my proposed fix for  viewToModel
                        viewToModel[base.Items[j]] = j;
                    }
                }
            }
            else
            {
                viewToModel = null;
                modelToView = null;
            }
        }

Specifications

  • Version: 2.8.3
  • Platform(s): WPF
  • Operating System(s): Windows 10,
@cwensley
Copy link
Member

Hey @desmetdirk, thanks for reporting the issue and finding the fix! Yes it is indeed not setting up the correct mapping there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants