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

Open
desmetdirk opened this issue Aug 19, 2024 · 0 comments

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,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant