Solved

How to select an item of a tree view as default?

Posted on 2008-10-14
15
387 Views
Last Modified: 2010-04-21
Hello.
        I have a virtual string tree component. In which I am creating some virtual node at run time. While loading the application I want to set the first item to be selected. Also I have another  virtual string tree component in the same view. This I am using as a grid view. I am loading some data  to the grid view according to the tree view selection. If the default item is selected then its corresponding data should be displayed in the grid view. I am using virtual tree view component from Softgems.
0
Comment
Question by:MAdhu
  • 7
  • 7
15 Comments
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 22711075
Download the demos for this components from softgems.
There are a couple of demos but look in the one with the folder  "Demos\Advanced" and run this demo.
Select the fourth demo option image along the top called "Hide and show nodes / Sync two trees".
This demo is exactly what you are looking for as it syncs a treeview and a grid view together.
0
 
LVL 28

Expert Comment

by:2266180
ID: 22711119
you slect the first node with:

  virtualstringtree1.Selected[virtualstringtree1.GetFirst]:=true;

then, for filling the second tree view, you set the first treeviews onclick event nad in that event you access the selected node by
virtualstringtree1.GetFirstSelected
and fill in the treeview as you need
0
 

Author Comment

by:MAdhu
ID: 22718130
Ok Ciuly. its working fine. if we want to select a default level 2 node(one child item). Then, what to do?
I tried something like this. virtualstringtree1.Selected[virtualstringtree1.GetFirstVisibleChild(Node)]:=true;
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 15

Expert Comment

by:mikelittlewood
ID: 22718788
Do you want to select the default child node of the very first root node in the tree, or from any currently selected node?
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 22718813
var
   currentNode: PVirtualNode;
begin
   currentNode := virtualstringtree1.focusedNode;
   virtualstringtree1.selected[ virtualstringtree1.getFirstVisibleChild( currentNode)] := true
0
 

Author Comment

by:MAdhu
ID: 22718963
yeah something like you told. Actually I have tree structure like below

NodeLevel1
          NodeLevel2
                  NodeLevel3
                  NodeLevel3
          NodeLevel2
                  NodeLevel3

I want to select first nodelevel3.
0
 

Author Comment

by:MAdhu
ID: 22719180
Its ok now. I did something like this

currentNode:= virtualstringtree1.GetFirst ;
   currentNode:= currentNode.FirstChild ;
    currentNode:= virtualstringtree1.GetFirstChild(currentNode);
    virtualstringtree1.Selected [pSelectedNode] := True ;
    virtualstringtree1.Focused ;
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 22719263
I was going to give you something similar to this yes, but you don't need your very last line. That is just to retrieve the currently selected node.
0
 

Author Comment

by:MAdhu
ID: 22719298
Yes its true. But now the exact problem is GetText event of the second virtualstringtree2 is not triggering according to the selection made.
0
 
LVL 15

Accepted Solution

by:
mikelittlewood earned 250 total points
ID: 22719312
In fact you could just repeat line 2 again to get the next child I would have though. Try to stick to one technique.

either:
   currentNode := virtualstringtree1.getFirst;
   currentNode := currentNode.firstChild;
   currentNode := currentNode.firstChild;
or:
   currentNode := virtualstringtree1.getFirst;
   currentNode := virtualstringtree1.getFirstChild( currentNode);
   currentNode := virtualstringtree1.getFirstChild( currentNode);
then finally
   virtualstringtree1.selected[ currentNode] := true;
0
 

Author Comment

by:MAdhu
ID: 22719547
But now the exact problem is GetText event of the second virtualstringtree2 is not triggering according to the selection made in virtualstringtree1.
0
 

Author Closing Comment

by:MAdhu
ID: 31505848
Thanks.
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 22719913
How are you selecting the item in the second tree in response to a change in the first tree?
Are you using the onChange event of the first tree?
Have you looked at the free demo that comes with the component on how to sync multiple trees?
0
 

Author Comment

by:MAdhu
ID: 22720465
yes by calling the onChange event of the first tree. Some issues are still there. But I can manage. Thanks
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 22721671
Ok glad I could help.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi cmd execution 6 60
indy Tmemory stream non latin charcter issue 2 110
can't find the executable in Simulator 1 90
Firemonkey DbLookupComboBox equivalent ? 2 47
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question