Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi TVirtualStringTree -> TStringGrid (https://www.delphipraxis.net/129167-tvirtualstringtree-tstringgrid.html)

hoika 13. Feb 2009 19:14


TVirtualStringTree -> TStringGrid
 
Hallo,

ich will ein TVirtualStringTree in ein TStringGrid umformen.
Er ist wie ein ListView aufgebaut (ein RootNode, kein Baum).

Ich bin bisher soweit.


Delphi-Quellcode:
class procedure TListViewToolClass.LVToGrid(
  theListView: TVirtualStringTree; theStringGrid: TStringGrid);
var
  iCurCol : Integer;
  iCurRow : Integer;
  Node   : PVirtualNode;
  sText  : String;
begin
  theStringGrid.ColCount:= theListView.Header.Columns.Count;
  theStringGrid.RowCount:= theListView.RootNode.ChildCount+1;

  for iCurCol:= 0 to theListView.Header.Columns.Count-1 do
  begin
    theStringGrid.Cells[iCurCol, 0]:= theListView.Header.Columns[iCurCol].Text;

    for iCurRow:= 0 to theListView.RootNode.ChildCount-1 (?) do
    begin
      if Assigned(theListView.OnGetText) then
      begin
        Node:= theListView.RootNode. (?)
        theListView.FOnGetText(Self, Node, iCurCol, TextType, sText);
      end;
    end;
  end;
end; { TListViewToolClass.LVToGrid }

Bei der folgenden Zeile hänge ich.
Delphi-Quellcode:
for iCurRow:= 0 to theListView.RootNode.ChildCount-1 (?) do
Wie bekomme ich die Zeilenzahl raus ?

Danke


Heiko

Hawkeye219 13. Feb 2009 19:39

Re: TVirtualStringTree -> TStringGrid
 
Hallo Heiko,

ich würde so vorgehen:

Delphi-Quellcode:
var
  Col, Row : Integer;
  Node    : PVirtualNode;
begin
  Grid.RowCount := VST.RootNodeCount + 1;
  Grid.ColCount := VST.Header.Columns.Count;

  for Col := 0 to Grid.ColCount - 1 do
    Grid.Cells[Col, 0] := VST.Header.Columns[Col].Text;

  Row := 1;
  Node := VST.GetFirst;
  while Assigned(Node) do
    begin
      for Col := 0 to Grid.ColCount -1  do
        Grid.Cells[Col, Row] := VST.Text[Node, Col];
      Inc (Row);
      Node := Node.NextSibling;
    end;
end;
Gruß Hawkeye

hoika 13. Feb 2009 20:01

Re: TVirtualStringTree -> TStringGrid
 
Hallo,

habe gerade selber eine Lösung hinbekommen.

Trotzdem Danke


Heiko


Delphi-Quellcode:
class procedure TListViewToolClass.LVToGrid(
  theListView: TVirtualStringTree; theStringGrid: TStringGrid);
var
  iCurCol : Integer;
  iCurRow : Integer;
  Node   : PVirtualNode;
  sText  : UnicodeString;
begin
  theStringGrid.ColCount:= theListView.Header.Columns.Count;
  theStringGrid.RowCount:= theListView.RootNode.ChildCount+1;

  for iCurCol:= 0 to theListView.Header.Columns.Count-1 do
  begin
    theStringGrid.Cells[iCurCol, 0]:= theListView.Header.Columns[iCurCol].Text;

    Node:= NIL;

    for iCurRow:= 0 to theListView.RootNodeCount-1 do
    begin
      if iCurRow=0 then
      begin
        Node:= theListView.RootNode.FirstChild;
      end
      else
      begin
        Node:= Node.NextSibling;
      end;

      if Assigned(theListView.OnGetText) then
      begin
        theListView.OnGetText(theListView, Node, iCurCol, ttNormal, sText);

        theStringGrid.Cells[iCurCol, iCurRow+1]:= sText;
      end;
    end;
  end;
end; { TListViewToolClass.LVToGrid }


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:14 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz