Skip to content

SelectedCount is not always correct #1197

@BigAl66

Description

@BigAl66
procedure TMyForm.vstStateChange(Sender: TBaseVirtualTree; Enter, Leave: TVirtualTreeStates);
var
  SelectedCount: Integer;
begin
  if tsChangePending in Leave then
  begin
    SelectedCount := 0;
    for var Node in vst.SelectedNodes do
      Inc(SelectedCount);
    if SelectedCount <> vst.SelectedCount then
      raise Exception.CreateFmt('counted=%d, vst=%d ', [SelectedCount, vst.SelectedCount]);
  end;
end;

Of course, multiselect is active. The code above throws an exception when I reduce the number of selected Items with <cursor up/down>. In that case the vst.SelectedCount still holds the old number while the counted items (SelectedCount) is correct.

If I check vst.SelectedCount later, it seems to be correct again. However, I can't find any later event fired by the vst component to check the count and respond to it.

OnAddToSelection and OnRemoveFromSelection don't work either. Again, the vst.SelectedCount is wrong.

It would be great to have an "OnAfterSelect" event that fires when everything is ready...

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugPull Requests InvitedThere are no current plans to address the issue, but we would be happy if someone supplies a PR.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions