1 (edited by AD1408 2019-07-29 05:04:25)

Topic: Moving Tree Nodes and Using one Tree only?

Hello all,


I've tried to move selected tree nodes up and down using Dmitry's script for table items but didn't work. Could anybody help please?


Also, I'd like not to use second tree on details form. Selecting the node to add item on form1 tree only. How could I do it?


Please see the attached sample project.

Post's attachments

Attachment icon TreeView Dmitry Ftrs.zip 9.14 kb, 306 downloads since 2019-07-25 

Adam
God... please help me become the person my dog thinks I am.

Re: Moving Tree Nodes and Using one Tree only?

Hi Dmitry,


Any solution?

Adam
God... please help me become the person my dog thinks I am.

3 (edited by sibprogsistem 2019-07-29 15:23:01)

Re: Moving Tree Nodes and Using one Tree only?

AD1408 wrote:

Hi Dmitry,


Any solution?

record_count1 := SQLExecute('SELECT record_count FROM OrgStructure WHERE id='+IntToStr(id1));
        showMessage(record_count1);
        record_count2 := SQLExecute('SELECT record_count FROM OrgStructure WHERE id='+IntToStr(id2));
        showMessage(record_count2);

is empty!


http://myvisualdatabase.com/forum/misc.php?action=pun_attachment&item=5671&download=0

Post's attachments

Attachment icon Безымянный.png 15.05 kb, 135 downloads since 2019-07-29 

Re: Moving Tree Nodes and Using one Tree only?

Hi sibprogsistem,

Thanks a lot for your reply, but I don't understand fully your suggestion.

Could you use the sample project and apply both question's solutions and post here please.

Adam
God... please help me become the person my dog thinks I am.

Re: Moving Tree Nodes and Using one Tree only?

Hi AD1408,

what he means ist that the record_count is empty... so there is no chance of getting a position.

For moving up or down you should probably use the treeview.moverow procedure...

BR

Re: Moving Tree Nodes and Using one Tree only?

Hi BR,

Thanks for the reply...
However, I still have no idea of how to do it.
Could somebody apply it to sample project (post #1)  and post it here please?

Adam
God... please help me become the person my dog thinks I am.

Re: Moving Tree Nodes and Using one Tree only?

AD1408 wrote:

Hi BR,

Thanks for the reply...
However, I still have no idea of how to do it.
Could somebody apply it to sample project (post #1)  and post it here please?

только это

procedure Form1_Button6_OnClick (Sender: string; var Cancel: boolean);
var
    id1, id2: integer;
    record_count1, record_count2, parent, parent2: string;
begin
    if (Form1.TreeView1.SelectedRow > 0) then
    begin
        id1 := Form1.TreeView1.dbItemID;
        id2 := Form1.TreeView1.dbIndexToID(Form1.TreeView1.SelectedRow-1);

        parent:=SQLExecute('SELECT IFNULL (ParentID,0) FROM OrgStructure WHERE id='+IntToStr(Form1.TreeView1.dbItemID));

        record_count1 := SQLExecute('SELECT  id FROM OrgStructure WHERE id='+IntToStr(id1)+' AND ParentID='+parent);
        record_count2 := SQLExecute('SELECT  id FROM OrgStructure WHERE id='+IntToStr(id2)+' AND ParentID='+parent);

        showmessage(record_count1);
        showmessage(record_count2);

        if (record_count1<>'') and (record_count2<>'') then
        begin
            SQLExecute('UPDATE OrgStructure SET id="0" WHERE id='+IntToStr(Form1.TreeView1.dbItemID));
            SQLExecute('UPDATE OrgStructure SET id='+record_count1+' WHERE id='+IntToStr(id2));
            SQLExecute('UPDATE OrgStructure SET id='+record_count2+' WHERE id="0"' );
            Form1.TreeView1.dbUpdate;
            Form1.TreeView1.dbItemID := id1;
        end;
    end;
end;
Post's attachments

Attachment icon TreeView Dmitry Ftrs.7z 6.68 kb, 330 downloads since 2019-07-31 

Re: Moving Tree Nodes and Using one Tree only?

Hi BR,


Thank you very much....
Truly appreciated.......

Adam
God... please help me become the person my dog thinks I am.

Re: Moving Tree Nodes and Using one Tree only?

Hi BR,


Once again thank you very much for your kind help.


Now, is it possible to move up and down main and second, third etc., levels nodes also? if so, how?

Adam
God... please help me become the person my dog thinks I am.

Re: Moving Tree Nodes and Using one Tree only?

procedure Form1_Button6_OnClick (Sender: string; var Cancel: boolean);
var
    id1, id2, row: integer;
    record_count1, record_count2, parent, parent2: string;
begin
    if (Form1.TreeView1.SelectedRow > 0) then
    begin
        id1 := Form1.TreeView1.dbItemID;
        id2 := Form1.TreeView1.dbIndexToID(Form1.TreeView1.SelectedRow-1);

        parent:=SQLExecute('SELECT IFNULL (ParentID,0) FROM OrgStructure WHERE id='+IntToStr(Form1.TreeView1.dbItemID));
        parent2:=SQLExecute('SELECT IFNULL (ParentID,0) FROM OrgStructure WHERE id='+IntToStr(id2));


        if parent2>parent then begin
         row:=Form1.TreeView1.SelectedRow-1;
          while parent2>parent do
           begin
            row:= row-1;
            id2 := Form1.TreeView1.dbIndexToID(row);
            parent2:=SQLExecute('SELECT IFNULL (ParentID,0) FROM OrgStructure WHERE id='+IntToStr(id2));
          end;
        end;

        record_count1 := SQLExecute('SELECT  id FROM OrgStructure WHERE id='+IntToStr(id1)+' AND ParentID='+parent);
        record_count2 := SQLExecute('SELECT  id FROM OrgStructure WHERE id='+IntToStr(id2)+' AND ParentID='+parent);


        if (record_count1<>'') and (record_count2<>'') then
        begin

            SQLExecute('UPDATE OrgStructure SET id="0" WHERE id='+IntToStr(Form1.TreeView1.dbItemID));
            SQLExecute('UPDATE OrgStructure SET id='+record_count1+' WHERE id='+IntToStr(id2));
            SQLExecute('UPDATE OrgStructure SET id='+record_count2+' WHERE id="0"' );
            Form1.TreeView1.dbUpdate;
            Form1.TreeView1.dbItemID := id1;
       end;
    end;
end;

Re: Moving Tree Nodes and Using one Tree only?

Hi sibprogsistem,


Thanks for the script... However, it doesn't do anything different other than moving child nodes, unless I'm doing something wrong.

Adam
God... please help me become the person my dog thinks I am.

Re: Moving Tree Nodes and Using one Tree only?

AD1408 wrote:

Hi sibprogsistem,


Thanks for the script... However, it doesn't do anything different other than moving child nodes, unless I'm doing something wrong.

Да, к сожалению я не могу понять как узлы связаны с записями..

Re: Moving Tree Nodes and Using one Tree only?

Hi Dmitry,


For the time being, could you post a sample project that demonstrates moving treeview component nodes up-down with button click event please. At least same level nodes move.

Adam
God... please help me become the person my dog thinks I am.

Re: Moving Tree Nodes and Using one Tree only?

AD1408 wrote:

Hi Dmitry,


For the time being, could you post a sample project that demonstrates moving treeview component nodes up-down with button click event please. At least same level nodes move.

Hello.


Example for you, you can move nodes at the same level.

Post's attachments

Attachment icon TreeView change position.zip 10.25 kb, 309 downloads since 2019-08-30 

Dmitry.

Re: Moving Tree Nodes and Using one Tree only?

Great stuff Dmitry..................
Thank you very much......................
Truly appreciated..................................

Adam
God... please help me become the person my dog thinks I am.

16 (edited by AD1408 2019-08-30 22:15:30)

Re: Moving Tree Nodes and Using one Tree only?

Hi Dmitry,


I have one issue that I cannot solve.
In your example " TreeView change position.zip " treview right click pop-up menu for adding top, child etc item takes us to frmOrg where there is hidden record count field. However, at my end same pop-up menu takes me some default window containing 1 field "Enter value". Without record count field on frmOrg, moving nodes doesn't work.
I'm using MVD 5.6.


Edit:
Sorry Dmitry, It seems that I missed to associate the form via treview form property

Adam
God... please help me become the person my dog thinks I am.