2011-04-10 27 views

Respuesta

25

Simplemente necesita llamar al FullExpand() en la vista de árbol.

+0

¿Cómo salto al primer elemento cuando se expande no al final? La barra de desplazamiento está en la parte inferior máxima. – Hidden

+2

@TheAllSeeingEye Quizás usando 'TopItem' y/o' Select'. –

+0

@Hidden: No puedo resolver el problema con la barra de desplazamiento. Estaba probando estas dos cosas, pero todavía tengo este problema. 'tvTreeView.Selected: = tvTreeView.TopItem'or' tvTreeView.Select (tvTreeView.Item [0]) '- no funciona para mí. ¿Cómo lo arreglaste? – astack

1

Al añadir NodoArbol hacer su propiedad ampliado a cierto

se encuentra una propiedad para el objeto TreeNode, yo puso cierto antes de añadir a la lista de nodos.

y también se puede encontrar un método para la vista de árbol llamada ExpandAll

de mi parte


probar este código

//this will expand all nodes of Level and their parents 
procedure ExpandTree(Tree: TTreeView; Level: integer); 

    procedure ExpandParents(Node: TTreeNode); 
    var 
    aNode : TTreeNode; 
    begin 
    aNode := Node.Parent; 
    while aNode <> nil do begin 
     if not aNode.Expanded then 
     aNode.Expand(false); 
     aNode := aNode.Parent; 
    end; 
    end; 

var 
    aNode : TTreeNode; 
begin 
    if Tree.Items.Count > 0 then begin 
    aNode := Tree.Items[0]; 

    while aNode <> nil do begin 
     if aNode.Level = Level then begin 
     aNode.Expand(false); 
     ExpandParents(aNode); 
     end; 
     aNode := aNode.GetNext; 
    end; 
    end; 
end; 

//this will expand the Node and it's parents 
procedure ExpandNode(Node: TTreeNode); 
var 
    aNode : TTreeNode; 
begin 
    Node.Expand(false); 

    aNode := Node.Parent; 
    while aNode <> nil do begin 
    if not aNode.Expanded then 
     aNode.Expand(false); 
    aNode := aNode.Parent; 
    end; 
end; 

y ver la referencia http://www.delphipages.com/forum/showthread.php?t=159148

Mi Saludos

+0

TTreeView no tiene método ExpandAll. Todos los objetos de TreeViw se agregaron en el tiempo de diseño – Funtime

+1

En StackOverflow no es necesario usar/pre o lo que sea para formatear el código. Todo lo que necesita hacer es sangrarlo por cuatro espacios. También ayudaría si no usara pestañas pero espacios para sangrar sus declaraciones. Para el código en línea, puede rodear el código con caracteres de "cita inversa". La cita hacia atrás (\ ') generalmente se encuentra junto con la tilde (~). La cita posterior también se puede usar en comentarios: 'like so'. –

0

Existen varias maneras de hacerlo. La forma más fácil sería

TreeView1.FullExpand; 

como en la respuesta aceptada - Como alternativa

if TreeView1.items.GetFirstNode <> nil then 
    TreeView1.items.GetFirstNode.Expand(True); 

o

if TreeView1.items[0] <> nil then 
    TreeView1.items[0].Expand(True); 

El Expandir método en un TTreeNode es útil si desea ampliar completamente de una determinada nodo que no es el nodo raíz.

Cuestiones relacionadas