Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sun Sep 15, 2019 9:08 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: einhugur Treeview
PostPosted: Mon May 24, 2010 4:08 pm 
Offline

Joined: Mon Apr 19, 2010 12:58 pm
Posts: 92
Hi,

I am trying to use this plugin, using the code below to populate the tree view.

Dim node as TreeViewNode
Dim node2 as TreeViewNode
Dim node3 As TreeViewNode

me.ColumnHeaderText(0) = "Manuals V2"

node = new TreeViewNode("Aarrow",Folder)
node.AppendNode(new TreeViewNode("Modelc",Document))
node.AppendNode(new TreeViewNode("Modeld",Document))
node.AppendNode(new TreeViewNode("Modele",Document))
node.AppendNode(new TreeViewNode("Modelf",Document))

node2 = new TreeViewNode("Baxi",Folder)
node2.AppendNode(new TreeViewNode("Modelc",Document))
node2.AppendNode(new TreeViewNode("Modeld",Document))
node2.AppendNode(new TreeViewNode("Modele",Document))
node2.AppendNode(new TreeViewNode("Modelf",Document))

node3 = new TreeViewNode("Carver",Folder)
node3.AppendNode(new TreeViewNode("Modelc",Document))
node3.AppendNode(new TreeViewNode("Modeld",Document))
node3.AppendNode(new TreeViewNode("Modele",Document))
node3.AppendNode(new TreeViewNode("Modelf",Document))

node.SetExpanded(false,false)
node2.SetExpanded(false,false)
node3.SetExpanded(false,false)


me.AppendNode(node)
me.AppendNode(node2)
me.AppendNode(node3)


It just doesnt seem right and this way is going to take alot to get 7000 items, would any experienced with this plugin please give some better suggestions, all the examples provided are the same and do not really show how to populate from a root.

Regards

John


Top
 Profile  
Reply with quote  
 Post subject: Re: einhugur Treeview
PostPosted: Mon May 24, 2010 4:36 pm 
Offline
User avatar

Joined: Fri Sep 30, 2005 11:48 am
Posts: 3554
Location: Lenexa, KS
I suggest you come up with a data representation of the data and then load the TreeView that way. What you're doing is correct, but you really don't want to have 7000 lines of code to do the same thing over and over again when all you really need to do is call the same bit of code over and over again with the proper data.

_________________
Bob K.

A blog about being a Real Studio/Xojo developer at http://www.bkeeneybriefs.com


Top
 Profile  
Reply with quote  
 Post subject: Re: einhugur Treeview
PostPosted: Mon May 24, 2010 4:44 pm 
Offline

Joined: Mon Apr 19, 2010 12:58 pm
Posts: 92
Hi,

Do you mean set it out in a text file and read into an array.


Regards

John


Top
 Profile  
Reply with quote  
 Post subject: Re: einhugur Treeview
PostPosted: Mon May 24, 2010 4:57 pm 
Offline
User avatar

Joined: Fri Sep 30, 2005 11:48 am
Posts: 3554
Location: Lenexa, KS
That is certainly 1 way of doing it. Or you can hardcode the array. The point is to not do the same code over and over again all 7000 times.

_________________
Bob K.

A blog about being a Real Studio/Xojo developer at http://www.bkeeneybriefs.com


Top
 Profile  
Reply with quote  
 Post subject: Re: einhugur Treeview
PostPosted: Mon May 24, 2010 7:32 pm 
Offline

Joined: Tue Oct 06, 2009 2:38 am
Posts: 435
I would recommend a database to represent the hierarchy especially if there are a lot of entries. It would be much cleaner from a maintenance and reporting standpoint.


Top
 Profile  
Reply with quote  
 Post subject: Re: einhugur Treeview
PostPosted: Tue May 25, 2010 1:41 am 
Offline

Joined: Mon Apr 19, 2010 12:58 pm
Posts: 92
Thank you

Regards
John


Top
 Profile  
Reply with quote  
 Post subject: Re: einhugur Treeview
PostPosted: Wed May 26, 2010 2:36 pm 
Offline

Joined: Mon Apr 19, 2010 12:58 pm
Posts: 92
Hi,

I took the suggestion to use a database, and found an example from a few years ago in this forum.

Used SQlite for database db1, with three fields. key_id,keyword and parent_id

I dropped the file into the project window.

Sub load_tree()
dim rs as RecordSet
dim id, parent as integer
dim keyword as string
dim node, child as TreeViewNode

TreeView1.RemoveAllNodes

rs= db.SQLSelect("select * from keywords order by parent_id, keyword")

while not rs.EOF // this line causes a NilObjectException **************************
id= rs.Field("key_id").IntegerValue
keyword= rs.Field("keyword").StringValue
parent= rs.Field("parent_id").IntegerValue

// Parameter was missing
child= new TreeViewNode(keyword)

child.ItemData= id
if parent= 0 then
// root level node
TreeView1.AppendNode child

// elseif eliminated, because node is Nil on first entering

else
// find the parent
node= find_node(parent)
node.AppendNode child
end
rs.MoveNext
wend

End Sub


Function find_node(parent as integer) As TreeViewNode
// iterate over root level nodes
dim node as TreeViewNode
dim i as integer

for i= 0 to TreeView1.RootNodeCount- 1

// RootNodes instead of RootNode

node= TreeView1.RootNodes(i)
if node.ItemData= parent then exit
node= find_node(node, parent)
if node<> nil then exit
next

return node
End Function


Function find_node(node as TreeViewNode, parent as integer) As TreeViewNode
// recurse through child nodes
dim child as TreeViewNode
dim i as integer

for i= 0 to node.NodeCount-1
child= node.node(i)
if child.ItemData= parent then exit
child= find_node(child, parent)
if child<> nil then exit
next

return child

End Function


and in the open event of the treeview control

load_tree


I keep getting a NilObjectException from this line:- while not rs.EOF // this line causes a NilObjectException ************************** in the Sub load_tree

Any thoughts please.

Regards

John


Top
 Profile  
Reply with quote  
 Post subject: Re: einhugur Treeview
PostPosted: Wed May 26, 2010 2:49 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
If you're getting an exception on that line, it means that rs is nil.
If rs is nil, it means that there was an error in the SQLSelect.

Examine the value of db.ErrorMessage
Make sure that db has a valid DatabaseFile
Make sure that db has been Connect'ed
Make sure that the file actually contains a table named "keywords"

Tim


Top
 Profile  
Reply with quote  
 Post subject: Re: einhugur Treeview
PostPosted: Wed May 26, 2010 5:38 pm 
Offline

Joined: Mon Apr 19, 2010 12:58 pm
Posts: 92
Hi Tim,

Thankyou, I did not notice the table reference "keywords", mine in the database was different.

That has cleared that problem but now the debugapp crashes on completion. No error message from RB just Windows Vista

Problem signature:
Problem Event Name:&nbsp; &nbsp;APPCRASH
Application Name:&nbsp; &nbsp;DebugMy Application.exe
Application Version:&nbsp; &nbsp;1.0.0.0
Application Timestamp:&nbsp; &nbsp;4bd89424
Fault Module Name:&nbsp; &nbsp;StackHash_c9c4
Fault Module Version:&nbsp; &nbsp;0.0.0.0
Fault Module Timestamp:&nbsp; &nbsp;00000000
Exception Code:&nbsp; &nbsp;c0000005
Exception Offset:&nbsp; &nbsp;00000000
OS Version:&nbsp; &nbsp;6.0.6000.2.0.0.768.3
Locale ID:&nbsp; &nbsp;2057
Additional Information 1:&nbsp; &nbsp;c9c4
Additional Information 2:&nbsp; &nbsp;77b42571e72e7c5327d3891f6667c8d7
Additional Information 3:&nbsp; &nbsp;0375
Additional Information 4:&nbsp; &nbsp;048361116c0178c9331ca2b6385bdbde


I ran a few breakpoints and it appears to be reading the file correct, built the app just to try and same result.
I think I will reduce the info in the database and run all the way through with breakpoints.

Thanks for your help( and your original code example)

Regards

John


Top
 Profile  
Reply with quote  
 Post subject: Re: einhugur Treeview
PostPosted: Fri May 28, 2010 2:37 am 
Offline

Joined: Mon Apr 19, 2010 12:58 pm
Posts: 92
Hi,

The code will form a treeview of parent nodes but crashes if the database has children.

Running through the debugger it appears to follow the code, but my inexperience doesnt help.
Would someone be willing to try running through the project and see if the problem is actually the code.

You can download the project file and database from here:

http://www.john-wheeler.co.uk/treeview.zip

I have continued to debug this code and have stepped into every piece, the parents are added correctly and as soon as it gets to node.AppendNode child does it fail, the screen shot shows it at this point, the variables and indexs are correct and I cannot figure why it fails.
Any comments would be appreciated good or bad.

Image


Regards

John


Top
 Profile  
Reply with quote  
 Post subject: Re: einhugur Treeview
PostPosted: Sun May 30, 2010 12:20 pm 
Offline

Joined: Mon Apr 19, 2010 12:58 pm
Posts: 92
Hi,

Well I finally sorted out the problem and the code works fine.

Next problem, with 7000 records it takes 30 seconds for the application to form the tree.
I think it might be better if I just hard code the data unless someone can tell me a better way.

Regards

John


Top
 Profile  
Reply with quote  
 Post subject: Re: einhugur Treeview
PostPosted: Sun May 30, 2010 1:41 pm 
Offline
Real Software Engineer

Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7858
Location: Canada, Alberta, Near Red Deer
Sounds to me like maybe the dynamic loading example is more suited to what you want
In that you initially load the root nodes only.
Then, when a node is expanded, in the before node expanding event you query the database for everything that is an immediate sub node of the one being expanded and add those to it. They then show up as expected.
And so on as the tree is expanded.

That way you are not loading up potentially thousands of items that may not get looked at.
And you never need to load 100% of the data at once. Only load the little bits that can be visible at each click.

And load times should be very fast

_________________
Norman Palardy (Real Software)


Top
 Profile  
Reply with quote  
 Post subject: Re: einhugur Treeview
PostPosted: Sun May 30, 2010 1:58 pm 
Offline

Joined: Fri Dec 01, 2006 3:09 pm
Posts: 650
Location: Tennessee, USA
I have no idea what it is that you are trying to display but I do know that 7000 entries is a large amount in a single list. Is there no way to break this up into more finite groupings. I know I would be reluctant to present any form of listview containing that many items. Think of the person using the program having to scroll through that list trying to find that specific item wanted. Can you have something like a list of general topics, click on one and another list appears with the items within that topic. Something that keeps any one list at a much more reasonable size. Just a suggestion.


Top
 Profile  
Reply with quote  
 Post subject: Re: einhugur Treeview
PostPosted: Sun May 30, 2010 6:14 pm 
Offline

Joined: Mon Apr 19, 2010 12:58 pm
Posts: 92
Hi,

Thankyou for the replies.
Your method sounds good, I will delve back into the documentation to see if I can try it.


harriew.

Yes, it is a lot and yes it is divided into 180 categories,with sub items.

Regards

John


Top
 Profile  
Reply with quote  
 Post subject: Re: einhugur Treeview
PostPosted: Wed Jun 02, 2010 6:54 pm 
Offline

Joined: Mon Apr 19, 2010 12:58 pm
Posts: 92
Hi,
Went with the concept of dynamic loading and now loads the tree in a blink.

The root nodes are loaded and forced to have an expander, I now need to determine a double click on either the parent or the child node.

If it is the parent it should just expand, if the child it selects for opening a file.

I used this code in the doubleclick event to begin with

if node <> nil then
node.SetExpanded(not node.Expanded,true)
end if

and it works but causes a nil object exception in the BeforeNodeExpanding event.

So I then tried the following code.

dim brands() as string
dim fileName as string
Dim j as Integer
dim count as Integer

brands=array("Aarrow","Acv","Aga","Albion") // the parent nodes
j=Ubound(brands)

for count = 0 to j
if node.text = brands(count) then
node.SetExpanded(not node.Expanded,true)
else
fileName = Node.Text +".pdf" // the child nodes
end if
next


but this is still selecting all nodes, although doubleclicking a parent works.

I keep going over it but cannot see where I am going wrong.
Any suggestions welcome.

Thanks
John


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


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

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group