Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AutoExpand TreeView ?

Status
Not open for further replies.

Bamben

Programmer
Jul 22, 2009
70
IT
I am having real problems with getting a TreeNode to be expanded on startup of my exe. I have managed to make it never collapse after you have expanded it manually...


procedure TMainForm.TreeViewCollapsing(Sender: TObject; Node: TTreeNode;
var AllowCollapse: Boolean);
begin
AllowCollapse := false;
end; //This works!!




I have some of the attempts that I can remember:

var
N: TTreeNode;

N.Parent.Expand(True); // causes a fatal error

TreeView.FullExpand; // doesn't appear to have any effect

N := TTreeView(N.TreeView).Items.getFirstNode;// TTreeVeiw and TTreeNode incompatable apparently?!

N := N.getFirstChild;//fatal error

(I am putting them first In a procedure that happens on exe startup)


Does anyone know the correct way to do this?

ps: AutoExpand in the Object Inspector has no effect
 
TreeView.FullExpand;//This works!!!!!!

It has only high lighted my real problem though...an item in the tree view must be selected for my code to get past an 'if' or some other part in the code (to get to the next step)
 
my problem is that you have to select a node of the TreeView before one of my actions will exicute. I think that I have found the line that is responsable:

TreeView.Selected := N;//old code
TreeView.Items[1] := N;//new code

The new code gives me the error 'Cannot assign to a read only property'

I am guessing at this point!
 
TreeView.Select;

error 1: There is no overloaded version of 'Select' that can be called with these arguments

error 2:Cannot assign to a read only property
 
TreeView.Items.SetSelected(CurrentRegNode);//Undeclared Identifier (its a title of a procedure in ComCtrls, which is where TTreeView comes from!!!?)



TreeView.Items.Selected(True);//Missing operator or semicolon
(how missing??) TreeView.Items.Expand(True);//this works fine!!
 
how come it will let me only refer to some procedures in files like ComCtrls???
 
SEE!!! I found this in ComCtrls

procedure TCustomTreeView.SetSelected(Value: TTreeNode);
begin
if Value <> nil then
Value.Selected := True
else
TreeView_SelectItem(Handle, nil);
end;
 
Look at the above code in the last post...

It says 2 things:
(Value: TTreeNode)
Value.Selected := True

so I go and change it to this:
N: TTreeNode;
N.Selected := True; //Fatal error

Ive now exploded my head!!!!!!!!!!!!!!
 
I've set 'HideSelection' to False in the Object inspector for TreeView.

And wrote this code into my procedure:

TreeView.SetFocus;
TreeView.Selected := TreeView.Items[0];

although there are no errors, my TreeView node remains unselected by default.

:(
 
TreeView.Items.Item[0].Selected := True;
TreeView.SetFocus;
TreeView.Selected := TreeView.Items[0];


I have put this code inside my procedure that executes on the start on the exe.
it doesn't have a 'begin' or a 'end' of its own (I have stuck it at the start (after the first begin) of the procedure.

What happens is very strange...it changes the image index of the node to image 0! one thing that might be good though is that another node also appeared with the correct icon for the next step in my application! (ie: registeration successful)
 
Lol all I need to do is select the first node by default on start of the exe. then it registers automatically!

I am sleepy

 
In fact with the code like this if you un-select the node it turns back to the right image, then when you select it agin it turns in to the same wrong image lolololol???
 
what has kept me going this long is the fact that, if I were to leave my code unaltered; registering is done with a simple click on the TreeView ONE SINGLE CLICK!

so if its that simple then it SHOULD be just one simple line of code!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top