[英]How to select nothing by clicking the empty background?
I have a Virtual Treeview (eg TVirtualStringTree
). 我有一个虚拟树视图(例如
TVirtualStringTree
)。
Note: Of course multiselect is off; 注意:当然多选是关闭的; because they can only select zero or one items
因为他们只能选择零个或一个项目
MCRE: MCRE:
procedure TForm6.FormCreate(Sender: TObject);
var
vst: TVirtualStringTree;
begin
vst := VirtualStringTree1;
vst.RootNodeCount := 5;
vst.TreeOptions.SelectionOptions := vst.TreeOptions.SelectionOptions + [toFullRowSelect];
vst.Header.Options := vst.Header.Options + [hoVisible];
vst.Header.Columns.Add;
vst.Header.Columns.Add;
vst.Header.Columns.Add;
vst.Header.Columns.Add;
vst.Header.Columns.Add;
end;
This should work out-of-the-box if toAlwaysSelectNode is not set and toMultiSelect is set in TreeOption.SelectionOptions. 如果没有设置toAlwaysSelectNode并且在TreeOption.SelectionOptions中设置了toMultiSelect,那么这应该是开箱即用的。 Tested wit latest source.
测试了最新的来源。
In other cases simply call ClearSelection()
: 在其他情况下,只需调用
ClearSelection()
:
procedure TVisibilityForm.VST2MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if TBaseVirtualTree(Sender).GetNodeAt(Point(X, Y)) = nil then
TBaseVirtualTree(Sender).ClearSelection();
end;
This procedure in OnMouseDown
should work regardless of the settings, you just need toRightClickSelect
in TreeOptions.SelectionsOptions
for right click selection, otherwise it doesn't work properly. 此过程中
OnMouseDown
无论怎样设置应该工作,你只需要toRightClickSelect
在TreeOptions.SelectionsOptions
右点击选择,否则就不能正常工作。
procedure VSTMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button in [mbLeft, mbRight] then
VST.FocusedNode := VST.GetNodeAt(X, Y);
if Assigned(VST.FocusedNode) then
VST.TreeOptions.PaintOptions := VST.TreeOptions.PaintOptions - [toAlwaysHideSelection]
else
VST.TreeOptions.PaintOptions := VST.TreeOptions.PaintOptions + [toAlwaysHideSelection];
end;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.