sorting: fix Container.SetSortMethod (fixes #15627)

This is the backport of #5977 for Helix. The bug has already been there in Gotham so no real Helix regression but still a bug.