Home > Back-end >  Treeview node is data in the database, I how to increase the deletion data refresh treeview node
Treeview node is data in the database, I how to increase the deletion data refresh treeview node

Time:12-05

With the treeview1. Items. Not clear

CodePudding user response:

delphi7

CodePudding user response:

Use is ADOtable, when the first open the program using a query, can show the node, I use the treeview1. Items. After the clear again query node shows don't come out

CodePudding user response:

Treeview1. Items. The clear is to clear all the existing node;
"First open the program using a query, you can show the node", this should not you open the query is automatically loaded and populate the node data, there will be other code to handle node data, so only after you remove the original node data query again, certainly will not have a node,

See you just open the program after the query code behind it,

CodePudding user response:

There is a simple way to, you all code search "treeview1" where you can find on the operation process,

CodePudding user response:

Procedure TForm1. The show ();
Var
Node1, 2, node3 node4: TTreeNode;
I, j, k, l: Integer;
Id1, id2, id3: string;
The begin
Company:=';
GroupBox4. Hide;
GroupBox5. Hide;
ADOTable1. Active:=True;
ADOTable1. Filter:='Cstate=' + '0';
ADOTable1. Filtered:=True;
ADOTable2. Active:=True;
ADOTable3. Active:=True;
ADOTable4. Active:=True;
Try
TreeView1. Selected:=nil;
While not ADOTable1. Eof do
While not ADOTable2. Eof do
While not ADOTable3. Eof do
While not ADOTable4. Eof do
For I:=0 to ADOTable1. Do RecordCount - 1
The begin
Node1:=Treeview1. Items. The Add (nil, ADOTable1 FieldByName (" CompanyName "). AsString) are identical.
Node1. StateIndex:=1;
Node1. SelectedIndex:=ADOTable1. FieldByName (' CompanyID). AsInteger;
Id1:=ADOTable1 FieldByName (' CompanyID). AsString;
ADOTable2. Filter:='ToCompanyID=' + # 39 + id1 + # 39 + 'and Mstate=' + '0'.
ADOTable2. Filtered:=True;
For j:=0 to ADOTable2. Do RecordCount - 1
The begin
2:=TreeView1. Items. AddChildObject (node1, ADOTable2 FieldByName (' MainDepartmentName). AsString, nil);
2. StateIndex:=2;
2. SelectedIndex:=ADOTable2. FieldByName (' MainDepartmentID). AsInteger;
Id2:=ADOTable2 FieldByName (' MainDepartmentID). AsString;
ADOTable3. Filter:='ToMainDepartmentID=' + # 39 + id2 + # 39 + 'and MState=' + '0'.
ADOTable3. Filtered:=True;
For: k=0 to ADOTable3. Do RecordCount - 1
The begin
Node3:=TreeView1. Items. AddChildObject (2, ADOTable3 FieldByName (' SecondDepartmentName). AsString, nil);
Node3. StateIndex:=3;
Node3. SelectedIndex:=ADOTable3. FieldByName (' SecondDepartmentID). AsInteger;
Id3:=ADOTable3 FieldByName (' SecondDepartmentID). AsString;
ADOTable4. Filter:='ToDepartmentID=' + # 39 + id3 + # 39 + 'and Wstate=' + '0'.
ADOTable4. Filtered:=True;
For: l=0 to ADOTable4. Do RecordCount - 1
The begin
Node4:=TreeView1. Items. AddChildObject (node3, ADOTable4 FieldByName (' WorkerName '). AsString, nil);
Node4. StateIndex:=4;
Node4. SelectedIndex:=ADOTable4. FieldByName (' WorkerID). AsInteger;
ADOTable4. Next;
end;
ADOTable3. Next;
end;
ADOTable2. Next;
end;
ADOTable1. Next;
end;
Except,
ShowMessage (' no information ');
end;
TreeView1. FullExpand;
end;

CodePudding user response:

reference tanqth reply: 3/f
treeview1. Items. The clear is to clear all the existing node;
"First open the program using a query, you can show the node", this should not you open the query is automatically loaded and populate the node data, there will be other code to handle node data, so only after you remove the original node data query again, certainly will not have a node,

See you just open the program after the query code behind,

The above is my query code, cyclic query according to the statement in my add node statements,

CodePudding user response:

1, ADOTable1 to ADOTable4 Active:=True, you can again ADOTable1. First; Once, make sure that the first record,
2, didn't see you a heap of. While not ADOTable1 Eof the do is what want to do, especially in combination with the for I:=0 to ADOTable1. RecordCount - 1 do,

3, for I:=0 to ADOTable1. Do RecordCount - 1 circular manner to also can, if use while not ADOTable1 Eof do better;
4, 'ToDepartmentID=' + # 39 + id3 + # 39 + 'and Wstate=' + '0'. # 39 here, you can actually 'ToDepartmentID="' + id3 + ' ' 'and Wstate=0'. Such use;

Finally said once, we usually deal with tree, not so much to nested code, because sometimes we don't know how many tree level,

The following code reference only, the modified you,
 
Var
Node1, 2, node3 node4: TTreeNode;
Id1, id2, id3: string;
The begin
Company:=';
GroupBox4. Hide;
GroupBox5. Hide;
ADOTable1. Active:=True;
ADOTable1. Filter:='Cstate=' + '0';
ADOTable1. Filtered:=True;
ADOTable1. First;
ADOTable2. Active:=True;
ADOTable3. Active:=True;
ADOTable4. Active:=True;
Try
TreeView1. Selected:=nil;
While not ADOTable1. Eof do
The begin
Node1:=Treeview1. Items. The Add (nil, ADOTable1 FieldByName (" CompanyName "). AsString) are identical.
Node1. StateIndex:=1;
Node1. SelectedIndex:=ADOTable1. FieldByName (' CompanyID). AsInteger;
Id1:=ADOTable1 FieldByName (' CompanyID). AsString;
ADOTable2. Filter:='ToCompanyID=' '+ id1 +' ' 'and Mstate=0';
ADOTable2. Filtered:=True;
ADOTable2. First;
While not ADOTable2. Eof do
The begin
2:=TreeView1. Items. AddChildObject (node1, ADOTable2 FieldByName (' MainDepartmentName). AsString, nil);
2. StateIndex:=2;
2. SelectedIndex:=ADOTable2. FieldByName (' MainDepartmentID). AsInteger;
Id2:=ADOTable2 FieldByName (' MainDepartmentID). AsString;
ADOTable3. Filter:='ToMainDepartmentID=' '+ id2 +' ' 'and MState=0';
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related