There is a Tree View, MultiSelect:=true
.
If to select all items then it is impossible to unselect or to select again but others. I think I need to do TreeView1.Selected.Selected:=false;
on TForm1.TreeView1Click
. But how to know if a click was not on controls: items, buttons?
A video: http://liga-installer.realservers.info/select.mp4
Is a code below normal?
procedure TForm1.TreeView1Click(Sender: TObject);
var
Item: TTreeNode;
开发者_运维百科begin
Item :=TTreeView(Sender).GetNodeAt(TTreeView(Sender).ScreenToClient(Mouse.CursorPos).X,
TTreeView(Sender).ScreenToClient(Mouse.CursorPos).y);
if (not Assigned(Item)) and (TTreeView(Sender).SelectionCount>0) then TTreeView(Sender).Select(nil, []);
end;
Thanks!
You are supposed to hold down the Shift key while clicking the first selected item. You can also deselect one item at a time by Ctrl-clicking it.
But I agree it is counter-intuitive. I'd do
procedure TForm1.TreeView1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
i: Integer;
begin
if not Assigned(TreeView1.GetNodeAt(X, Y)) then
for i := 0 to TreeView1.Items.Count - 1 do
TreeView1.Items[i].Selected := false;
end;
精彩评论