2

I am using a VirtualStringTree control as a list view and using the sort features. However when I double click the VirtualStringTree header the sort direction symbol hides until I click the header again.

Can that behaviour be disabled?

Things that I have tried but do not work:

  • I have searched the properties and cannot find a related setting
  • I have linked the double click header event to the click header event

My environment is Delphi 2007 Pro, Windows 7 Pro 64bit.

TLama
  • 75,147
  • 17
  • 214
  • 392
Paul H
  • 23
  • 3

1 Answers1

1

I had the same issue with double-click and hiding of sorting triangle and instead I just wanted a simple toggle up/down with nothing else. This issue is present unfortunately in latest VirtualTreeView (4.8.7) as well.

Here is a bit of code that fixes the issue - put something like this in your OnHeaderClick event (not OnHeaderDblClick !).

The relevant line is if HitInfo.Column = NoColumn then Exit; which fixes the double-click problem. You may or may not use the rest of code for your own purposes but it may be useful to someone else. The rest of explanation is in the code comments.

You don't need to define OnHeaderDblClick event - it may be empty if not needed so you may want to remove that from your code.

UPDATE

Also read comments from TLama as it seems that with version 5.0.0. this fix may not operate as intended. With the current version it does though.

  {**
    A column header of a VirtualStringTree was clicked: Toggle the sort direction
  }
  procedure TMainForm.vstHeaderClick(Sender: TVTHeader; HitInfo: TVTHeaderHitInfo);
  begin

  // Don't call sorting procedure on right click
  // Some list-headers have a contextmenu which should popup then.
  if HitInfo.Button = mbRight then Exit;

  // Beginning with VT's r181, this proc is also called when doubleclicking-to-autofit
  // Seems buggy in VT as this suddenly calls it with Column=-1 in those cases.
  // See also issue #1150
  if HitInfo.Column = NoColumn then Exit;

  if Sender.SortColumn <> HitInfo.Column then Sender.SortColumn := HitInfo.Column
  else if Sender.SortDirection = sdAscending then Sender.SortDirection := sdDescending
  else Sender.SortDirection := sdAscending;

  Sender.Treeview.SortTree( HitInfo.Column, Sender.SortDirection );
  end;
Coder12345
  • 3,431
  • 3
  • 33
  • 73
  • In v. 4.8.7 the `OnHeaderDblClick` won't never be fired, there was an [issue](http://stackoverflow.com/a/7890884/960757). All of this is fixed in the [latest version](http://virtual-treeview.googlecode.com/svn/trunk/Source/VirtualTrees.pas) at this time. – TLama Dec 01 '11 at 14:04
  • With that all fixed I mean `OnHeaderDblClick` is now correctly fired and the problem with sort glyph disappearing at double click is removed. – TLama Dec 01 '11 at 14:46
  • +1, you're right it workarounds the problem, but don't forget that it won't toggle anything after the new version will be released ;) I'll delete my post from here, it seems to me that OP won't never come back :) – TLama Dec 01 '11 at 14:53
  • Thanks very much for the above solution and everyone's posts. I will plan to change to 5.0.0.0 but in the mean time using the above solution. Thanks Paul – Paul H Dec 02 '11 at 00:46