Reputation: 4127
I just need to deselect an item of a treeview in delphi.
Here my failed try:
1) TreeView1.Selected.Selected := False;
2) TreeView1.Selected.Data := nil;
3) TreeView1.Select(nil,[]);
4)
for i := 0 to TreeView1.Items.Count - 1 do
TreeView1.Items[i].Selected := false;
5)
TreeView1.MultiSelect := true;
for i := 0 to TreeView1.Items.Count - 1 do
TreeView1.Items[i].Selected := false;
TreeView1.MultiSelect := false;
6)
var
nulla : TTreeNode;
nulla := nil;
TreeView1.Select(nulla, []);
7) TreeView1.ClearSelection(False);
8) TreeView1.ClearSelection(True);
They ALL crash my program (except for 8, it simply doesn't do anything), how can i do this?
My goal is to simply deselect clicking on a white space.
Upvotes: 1
Views: 1848
Reputation: 595369
Setting the TTreeView.Selected
property to nil
, or setting the TTreeNode.Selected
property to False
, is the correct approach.
1 and 2 will crash if TTreeView.Selected
is already nil
, but the other approaches should work fine, provided that the TTreeView
pointer is a valid pointer to begin with.
Upvotes: 3