[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

3.0

Not just collapse the whole treeview but show only the main folders.

Asked by peterkiers in Delphi Programming

Dear Experts,

I have an application with a treeview, a richedit and 2 buttons on it.
The buttons are for making a file-node and a folder node in a treeview.
The treeview-nodes along with the text that will be displayed on the
richedit are being saved and loaded to a database.

My application works great, only one little detail that is not correct.
When I open a file(database) with my application it collapses the whole tree.
and I want just de main-folders. In the first picture I have put an example
of another programm that has it right, and the second picture is my application.
You can see the diffirence. Who can help me to solve this problem.

I have only put the code in the code-section that I think is relevant.

Greetings,

Peter Kiers
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
(*---------------------------------------------------*)
function CustomSortProc(Node1, Node2: TTreeNode; Data: Integer): Integer; stdcall;
begin
 if Node1.ImageIndex<>Node2.ImageIndex Then 
  begin
   if Node1.ImageIndex=Item_Image_Index Then Result:=-1 Else Result:=1;
  end Else
  Result:=AnsiCompareText(Node1.Text, Node2.Text);
end;
(*---------------------------------------------------*)
function TMainForm.FindNode(ni: integer): TTreeNode;
Var
 i:integer;
begin
 With treeview1 do for i := 0 to Items.Count - 1 do if ni=Integer(Items[i].Data) then
  begin
   Result:=Items[i];
   Exit;
  end;
 Result:=nil;
end;
(*---------------------------------------------------*)
procedure TMainForm.FormCreate(Sender: TObject);
var
  I: Integer;
  SOToken: ISpeechObjectToken;
  SOTokens: ISpeechObjectTokens;
begin
  DBPath := IncludeTrailingPathDelimiter(ExtractFilePath(Application.Exename));
  DBName := 'dbtree.pkr';
  Caption :='Untitled - IT Knowledgebase';
  PageControl1.ActivePage := Tabsheet1;
  OpenDatabase;
end;
(*---------------------------------------------------*)
procedure TMainForm.FormDestroy(Sender: TObject);
var
  I: Integer;
begin
 AdoTable1.First;
  for I := 0 to cbVoices.Items.Count - 1 do
    ISpeechObjectToken(Pointer(cbVoices.Items.Objects[I]))._Release;
end;
(*---------------------------------------------------*)
procedure TMainForm.LoadTree;
Var
  i:integer;
  n,n2:TTreeNode;
begin
 ADOTable1.First;
 With TreeView1 do
  begin
   Items.BeginUpdate;
   Items.Clear;
   while Not ADOTable1.Eof do
    begin
     n2:=FindNode(ADOTable1Parent.Value);
     n:=Items.AddChild(n2,ADOTable1Name.Value);
     n.ImageIndex:=ADOTable1Image_Index.Value;
     if n.ImageIndex = FolderClose_Image_Index
        Then n.SelectedIndex:=FolderOpen_Image_Index
        Else n.SelectedIndex:=n.ImageIndex;
     n.Data:=Pointer(ADOTable1ID.Value);
     ADOTable1.Next;
    end;
   for i:=0 to Items.Count-1 do Items[i].Expand(True);
      CustomSort(@CustomSortProc, 0);
   Items.EndUpdate;
  end;
  With TreeView1 do if Items.Count>0 Then Selected:=Items[0];
end;
(*---------------------------------------------------*)
procedure TMainForm.New1Click(Sender: TObject);
begin
  Caption :='Untitled - IT Knowledgebase';
  DBPath := IncludeTrailingPathDelimiter(ExtractFilePath(Application.Exename));
  DBName := 'dbtree.pkr';
  OpenDatabase;
end;
(*---------------------------------------------------*)
procedure TMainForm.NewFolder1Click(Sender: TObject);
Var
 n,n2:TTreeNode;
 NewText:String;
begin
 if (TreeView1.Selected<>nil) And (TreeView1.Selected.ImageIndex = Item_Image_Index ) Then Exit;
 NewText:=InputBox('New Folder','Folder Name','');
 if NewText='' Then Exit;
 n2:=TreeView1.Selected;
 n:=TreeView1.Items.AddChild(n2,NewText);    
 n.ImageIndex:=FolderClose_Image_Index;
 n.SelectedIndex:=FolderOpen_Image_Index;
 TreeView1.Selected:=nil;
 ADOTable1.Insert;
 ADOTable1Status.Value:=0;
 ADOTable1Name.Value:=n.Text;
 ADOTable1Image_Index.Value:=FolderClose_Image_Index;
 if Assigned(n2)
  Then ADOTable1Parent.Value:=Integer(n2.Data)
  Else ADOTable1Parent.Value:=0;
 ADoTable1.Post;
 n.Data:=Pointer(ADOTable1ID.Value);
 TreeView1.Selected:=n;
 if n.Parent=nil
  Then TreeView1.CustomSort(@CustomSortProc, 0,False)
  Else n.Parent.CustomSort(@CustomSortProc, 0,False);
end;
(*---------------------------------------------------*)
procedure TMainForm.NewItem1Click(Sender: TObject);
Var
 n,n2:TTreeNode;
 NewText:String;
begin
 if (TreeView1.Selected=nil) Or (TreeView1.Selected.ImageIndex <> FolderClose_Image_Index) Then Exit;
 NewText:=InputBox('New Item','Item Name','');
 if NewText='' Then Exit;
 n2:=TreeView1.Selected;
 n:=TreeView1.Items.AddChild(n2,NewText);
 n.ImageIndex:=Item_Image_Index;
 n.SelectedIndex:=Item_Image_Index;
 TreeView1.Selected:=nil;
 ADOTable1.Insert;
 ADOTable1Status.Value:=0;
 ADOTable1Name.Value:=n.Text;
 ADOTable1Image_Index.Value:=Item_Image_Index;
 if Assigned(n2)
  Then ADOTable1Parent.Value:=Integer(n2.Data)
  Else ADOTable1Parent.Value:=0;
 ADoTable1.Post;
 n.Data:=Pointer(ADOTable1ID.Value);
 TreeView1.Selected:=n;
 if n.Parent=nil
  Then TreeView1.CustomSort(@CustomSortProc, 0,False)
  Else n.Parent.CustomSort(@CustomSortProc, 0,False);
end;
(*---------------------------------------------------*)
procedure TMainForm.Open1Click(Sender: TObject);
var
  sFileName: String;
begin
  OpenDialog1.InitialDir := DBPath;
  if OpenDialog1.Execute then
  begin
    DBName := ExtractFileName(OpenDialog1.FileName);
    DBPath := ExtractFilePath(OpenDialog1.FileName);
    sFileName := OpenDialog1.FileName;
    MainForm.Caption := ExtractFileName(OpenDialog1.FileName) + ' - ' + 'IT Knowledgebase';
    updateRecent(sFileName);
    OpenDatabase;
  end;
end;
(*---------------------------------------------------*)
procedure TMainForm.OpenDatabase;
var
  conn_str:string;
begin
  conn_str :=
    Format('provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=%s%s;',
    [IncludeTrailingPathDelimiter(DBPath), DBName]);
  ADOConnection1.Connected := False;
  ADOConnection1.ConnectionString := conn_str;
  ADOConnection1.Connected := True;
  ADOTable1.Open;
  LoadTree;
end;
(*---------------------------------------------------*)
procedure TMainForm.TreeView1Change(Sender: TObject; Node: TTreeNode);
Var
 V:Variant;
 e:Boolean;
begin
 if Assigned(TreeView1.Selected) then
  begin
   V:=Integer(TreeView1.Selected.Data);
   if V>0 then ADOTable1.Locate('ID',V,[]);
   e:=TreeView1.Selected.ImageIndex=Item_Image_Index;
  end Else e:=False;
 DbRichEdit1.Enabled:=e;
 DbRichEdit2.Enabled:=e;
end;
(*---------------------------------------------------*)
procedure TMainForm.TreeView1Editing(Sender: TObject; Node: TTreeNode;
  var AllowEdit: Boolean);
begin
  AllowEdit := Node.Parent <> nil;
end;
(*---------------------------------------------------*)
Attachments:
 
Example1
Example1
 
 
Example2
Example2
 
[+][-]11/07/09 10:21 AM, ID: 25767373Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Delphi Programming
Sign Up Now!
Solution Provided By: Geert_Gruwez
Participating Experts: 2
Solution Grade: C
 
[+][-]11/07/09 10:31 AM, ID: 25767433Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/07/09 10:42 AM, ID: 25767485Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/07/09 11:54 PM, ID: 25769738Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/08/09 06:21 AM, ID: 25770554Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]11/08/09 10:29 AM, ID: 25771294Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/08/09 10:42 AM, ID: 25771342Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/08/09 11:06 PM, ID: 25773851Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/08/09 11:15 PM, ID: 25773889Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/08/09 11:20 PM, ID: 25773908Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/09/09 10:41 AM, ID: 25778667Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625