Einzelnen Beitrag anzeigen

Benutzerbild von DGL-luke
DGL-luke

Registriert seit: 1. Apr 2005
Ort: Bad Tölz
4.149 Beiträge
 
Delphi 2006 Professional
 
#8

Re: Virtual Treeview: COlumn-COllection wirft

  Alt 13. Feb 2007, 19:38
Öhm öhm... validaten... mach ich nirgends

wo sollte das am besten hin? in OnGetText? in OnInitNode? habs jetzt mal in OnInitNode gepackt. und es scheint nichts zu ändern.
Aber ich hab inzwischen meinen Code soweit hingebracht, dass er immerhin alles genau so anzeigt wie ichs haben will, sprich korrekt aus dem XML rausparst.

OK... mein Code kann ich zeigen:

Delphi-Quellcode:
type
  TNodeLevel = (nlNew=0,nlForm=1, nlFormProp=2, nlCompBranch=3, nlComponent=4,
                nlCompProp=5);

  PNodeData = ^TNodeData;
  TNodeData = record
    Level: TNodeLevel;
    Dummy: Integer;
  end;

procedure TLangTreeController.Init;
var
  i: Integer;
  LangNode: TJvSimpleXMLElem;
  OwnData: TNodeData;
begin
  LangNode := FXML.Root.Items.ItemNamed['languages'];

  SetLength(FActiveLangs,LangNode.Items.Count);
  for i := 0 to high(FActiveLangs) do
  begin
    FActiveLangs[i] := LangNode.Items[i].Properties.ItemNamed['ident'].Value;
  end;

  FTree.Clear;
  FTRee.Header.Columns.Clear;

  with FTree.Header.Columns.Add do
  begin
    Tag := -1;
    Text := 'Baum';
  end;

  for i := 0 to high(FActiveLangs) do
    with FTree.Header.Columns.Add do
    begin
      Text := FActiveLangs[i];
      Tag := i;
    end;

  FTree.NodeDataSize := SizeOf(TNodeData);
  
  OwnData.Level := nlForm;

  for i := 0 to FXML.Root.Items[1].Items.Count - 1 do
  begin
    FTree.ValidateNode(FTree.AddChild(nil,Pointer((@OwnData)^)),false);
  end;
end;

procedure TLangTreeController.VSTInitNode(Sender: TBaseVirtualTree; ParentNode,
  Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
var
  NodeData,ParentData: PNodeData;
  StrucElems: TJvSimpleXMLElems;
begin
  FTree.ValidateNode(Node, false);

  NodeData := Sender.GetNodeData(Node);

  if NodeData.Level <> nlForm then
  begin
    ParentData := Sender.GetNodeData(Node.Parent);
    StrucElems := FXML.Root.Items.ItemNamed['structure'].Items;

    case ParentData.Level of
      nlForm:
        if Node.Index < StrucElems[Node.Index].Items.ItemNamed['properties'].Items.Count then
          NodeData.Level := nlFormProp
        else
        if Node.Index = StrucElems[Node.Index].Items.ItemNamed['properties'].Items.Count then
          NodeData.Level := nlCompBranch;
      nlCompBranch:
          NodeData.Level := nlComponent;
      nlComponent:
          NodeData.Level := nlCompProp;
    end;
  end;

  case NodeData.Level of
    nlForm, nlComponent, nlCompBranch:
      InitialStates := InitialStates + [ivsHasChildren];
  end;
end;

procedure TLangTreeController.VSTInitChildren(Sender: TBaseVirtualTree;
  Node: PVirtualNode; var ChildCount: Cardinal);
var
  NodeData: PNodeData;
  StrucElem: TJvSimpleXMLElem;
begin
  NodeData := Sender.GetNodeData(Node);

  StrucElem := FXML.Root.Items.ItemNamed['structure'];

  case NodeData.Level of
    nlForm:
      //number of form properties and the <components> branch
      ChildCount := StrucElem.Items[Node.Index].Items.Count;
    nlFormProp,nlCompProp:
      //no childs to properties
      ChildCount := 0;
    nlCompBranch:
      //number of components
      // form = Node.Parent
      ChildCount := StrucElem.Items[Node.Parent.Index].Items
        .ItemNamed['components'].Items.Count;
    nlComponent:
      //number of properties
      // component = Node
      // form = Node.Parent.Parent
      ChildCount := StrucElem.Items[Node.Parent.Parent.Index]
        .Items.ItemNamed['components'].Items[Node.Index].Items.Count;
    else
      //if not sure, no childs.
      ChildCount := 0;
 end;
end;

Viel Spaß damit...

Übrigens: Ich habe zur zeit zwei rootnodes. wenn ich die erste bis in die dritte ebene ausklappe, bekomme ich bei jedem ausklappen die Av (also jedesmal, wenn ich auf das "+" klicke). Ich kann die dann auch nicht mehr einklappen. Dafür kann ich dann aber die zweite rootnode (und ihre childnodes) problemlos ein- und ausklappen.
Lukas Erlacher
Suche Grafiktablett. Spenden/Gebrauchtangebote willkommen.
Gotteskrieger gesucht!
For it is the chief characteristic of the religion of science that it works. - Isaac Asimov, Foundation I, Buch 1
  Mit Zitat antworten Zitat