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

toRestoreSelection works unexpected in case multiple items have the same name #981

Closed
joachimmarder opened this issue Jul 10, 2020 · 4 comments
Assignees
Milestone

Comments

@joachimmarder
Copy link
Contributor

Currently the code behind the toRestoreSelection uses the text of column 0 to restore the selection after a refill of the control.

In case multiple items with the same text exists, this produces unexpected results, e.g. more nodes are selected than it was orignally the case.

@joachimmarder
Copy link
Contributor Author

Proposed change: Introduce new public property RestoreSelectionUniqueColumn. The getter will return MainColumn unless the developer assigned another value.

@joachimmarder joachimmarder self-assigned this Jul 21, 2020
@joachimmarder joachimmarder added this to the V7.5 milestone Jul 21, 2020
@luebbe
Copy link
Contributor

luebbe commented Jul 22, 2020

Haven't looked at the code, but it sounds like the selected strings are stored for comparison. I guess you can never make sure that the values in a column are unique.
Would it make sense to have unique ids in the node instead?

@joachimmarder
Copy link
Contributor Author

joachimmarder commented Jul 28, 2020

Would it make sense to have unique ids in the node instead?

That would solve the issue comprehensively, but due to virtual nature of the control, this UID needs to be provided by the application, so that it stays the same after a refill of the control. And the ID needs to be stored with every node and consumes memory, but would be useful only in corner cases.

Therefore, the idea to use already existing information and allow the developer to mark one column as the one with unique information, instead of using a fix column index 0.

@Ajoschi
Copy link

Ajoschi commented Mar 29, 2021

@joachimmarder : 2 Lines of code in VirtualTrees.pas need to be adjusted in order to make this work as expected:

  1. TCustomVirtualStringTree.AddToSelection: Relative line 13 -> Pass "Header.RestoreSelectionColumnIndex" instead of 0 as 3rd Parameter to call Self.OnGetText()
  2. TCustomVirtualStringTree.RemoveFromSelection: Relative line 8-> Pass "Header.RestoreSelectionColumnIndex" instead of 0 as 3rd Parameter to call Self.OnGetText()

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

No branches or pull requests

3 participants