Components for Delphi and C++ Builder.

Go to Russian forum
Go to EhLib.com
It is currently 16 Apr 2024, 05:11

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: 20 Jul 2021, 18:44 
Offline

Joined: 15 Mar 2021, 16:33
Posts: 37
Hi

How can i display node CHILD2 with his childs(SUBCH1,SUBCH2(...),SUBCH3..4) in dbgridEh.

Note:Pls find the attachment.

Best Reagards

Thank you


Attachments:
tree_ehlib.jpg
tree_ehlib.jpg [ 55.27 KiB | Viewed 1117 times ]
Top
 Profile  
 
PostPosted: 20 Jul 2021, 20:39 
Offline

Joined: 08 May 2014, 18:06
Posts: 663
Hello

In your screenshot, CHILD2 is already showing his children.
Do you want some additional functionality?

_________________
Best regards
EhLib Support Team


Top
 Profile  
 
PostPosted: 20 Jul 2021, 20:56 
Offline

Joined: 15 Mar 2021, 16:33
Posts: 37
In the example display all the tree . what i want to display only the red box in dbgridEH.
How can i do it ?


Top
 Profile  
 
PostPosted: 21 Jul 2021, 23:13 
Offline

Joined: 08 May 2014, 18:06
Posts: 663
Hello

You need to have a copy of MemTableEh into which you need to copy only the necessary branches of the tree.

Here is an code and Demo project.

Code:
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, DBGridEhGrouping, ToolCtrlsEh,
  DBGridEhToolCtrls, DynVarsEh, MemTableDataEh, Data.DB, MemTableEh, EhLibVCL,
  GridsEh, DBAxisGridsEh, DBGridEh, Vcl.StdCtrls, Vcl.ExtCtrls;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    PaintBox1: TPaintBox;
    bReopen: TButton;
    Memo1: TMemo;
    bFilterNode: TButton;
    DBGridEh1: TDBGridEh;
    MemTableEh1: TMemTableEh;
    MemTableEh2: TMemTableEh;
    DataSource1: TDataSource;
    procedure FormCreate(Sender: TObject);
    procedure bReopenClick(Sender: TObject);
    procedure bFilterNodeClick(Sender: TObject);
    procedure DataSource1DataChange(Sender: TObject; Field: TField);
  private
    { Private declarations }
  public
    FilterRecViewMTE1: TMemRecViewEh;

    procedure ReloadMemTable2;
    function CheckRecordOrParent(RecView: TMemRecViewEh): Boolean;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ReloadMemTable2;
var
  I: Integer;
  RecView: TMemRecViewEh;
  J: Integer;
begin
  MemTableEh1.TreeList.FullExpand;

  MemTableEh2.DisableControls;
  MemTableEh2.EmptyTable;

  for I := 0 to MemTableEh1.RecordsView.Count - 1 do
  begin
    RecView := MemTableEh1.RecordsView.RecordView[I];

    if (CheckRecordOrParent(RecView)) then
    begin
      MemTableEh2.Append;
      for J := 0 to MemTableEh1.Fields.Count - 1 do
        MemTableEh2.Fields[J].Value := RecView.Rec.Value[J, dvvValueEh];
      MemTableEh2.Post;
    end;
  end;

  MemTableEh2.First;
  MemTableEh2.EnableControls;
end;

function TForm1.CheckRecordOrParent(RecView: TMemRecViewEh): Boolean;
var
  ParentRecView: TMemRecViewEh;
begin
  if (FilterRecViewMTE1 = nil) then
  begin
    //All Records
    Result := True;
    Exit;
  end;

  ParentRecView := RecView;
  while ParentRecView <> nil do
  begin
    if (ParentRecView = FilterRecViewMTE1) then
    begin
      Result := True;
      Exit;
    end;
    ParentRecView := ParentRecView.NodeParent;
  end;

  Result := False;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  FilterRecViewMTE1 := nil;
  ReloadMemTable2;
end;

procedure TForm1.bFilterNodeClick(Sender: TObject);
var
  RecId: Variant;
begin
  RecId := MemTableEh2.FieldByName('ID').Value;
  MemTableEh1.Locate('ID', RecId, []);
  FilterRecViewMTE1 := MemTableEh1.RecView;
  ReloadMemTable2;
end;

procedure TForm1.bReopenClick(Sender: TObject);
begin
  FilterRecViewMTE1 := nil;
  ReloadMemTable2;
end;

procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);
begin
  bFilterNode.Caption := 'Show "' + MemTableEh2.FieldByName('NODNAME').AsString + '" Node with Children';
end;

end.


Attachments:
DBGridEh.TeeView-ShowPartOfTheTree.zip [7.43 KiB]
Downloaded 77 times
sshot-197.png
sshot-197.png [ 14.23 KiB | Viewed 1101 times ]
sshot-196.png
sshot-196.png [ 24.45 KiB | Viewed 1101 times ]

_________________
Best regards
EhLib Support Team
Top
 Profile  
 
PostPosted: 22 Jul 2021, 07:59 
Offline

Joined: 15 Mar 2021, 16:33
Posts: 37
Thank you a lot.

Note:What i need only child2 and his nodes.

It is possible to display only child2 and his nodes only without root1 and child1 ?

Best regards


Top
 Profile  
 
PostPosted: 22 Jul 2021, 14:30 
Offline

Joined: 08 May 2014, 18:06
Posts: 663
Hello


Quote:
In the example display all the tree . what i want to display only the red box in dbgridEH.

Quote:
Note:What i need only child2 and his nodes.


Please write what is incorrectly displayed on the screenshot - sshot-197.png.

_________________
Best regards
EhLib Support Team


Top
 Profile  
 
PostPosted: 23 Jul 2021, 02:44 
Offline

Joined: 15 Mar 2021, 16:33
Posts: 37
Sorry. This is my mistake.
It work well and I got the idea.
Thank you a lot.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group