UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

3 Pages V   1 2 3 >  
Reply to this topicStart new topic
> Treeview control    
 
   
diegorodriguez
post Oct 21 2003, 04:47 AM
Post #1

UtterAccess Member
Posts: 30
From: Barcelona, Spain



Treeview is a very helpful way to build menus that allow users to quickly discover the new objects set up by programmers on the usual tree structure.

There are some examples on Treeview controls and associated visual basic code to perform several tasks that can be found at some microsoft sites, like this sample at

http://support.microsoft.com/default.aspx?...kb;EN-US;209898

Wish list:
In the attached TREE CONTROL.mdb example, based on above sample, and only containing a table and a form, TreeView is used to show a control panel populated based on a table, and its items can be moved around, changing its dependencies. But now, it would be nice to add an OnClick event so a form should be opened associated to each one of those items. And... even nicer if each item could be represented by an specific icon (a folder, or a packet, or anything...) that could even change if deployed. May anyone have an idea on how to do that?
Attached File(s)
Attached File  CONTROL TREE.zip ( 392.89K ) Number of downloads: 1158
 
Go to the top of the page
 
+
Marto
post Oct 21 2003, 05:53 AM
Post #2

UtterAccess Veteran
Posts: 352
From: Dublin, Ireland



Hi,
Check this out web page

HTH
Martin

P.S This is from a thread in UI Design, unfortunately I don't know how to point to that thread
Go to the top of the page
 
+
diegorodriguez
post Oct 22 2003, 02:34 AM
Post #3

UtterAccess Member
Posts: 30
From: Barcelona, Spain



Those examples consist of a form its code for Access 9, 2000 and 2003, but they do not seem to run without tables. 'The control has no objects'. The working form looks nice, as you can see following this link from Mr.Sherwood.

http://www.personal.rdg.ac.uk/~shssherd/databases.htm

How can I make them work?
Go to the top of the page
 
+
pwrsales
post Oct 22 2003, 04:07 AM
Post #4

UtterAccess Member
Posts: 34
From: Belgium



Great job! I wonder do you make use of the MStoolbar control also by any chance?

Best regards

Frank
Go to the top of the page
 
+
diegorodriguez
post Oct 22 2003, 08:53 AM
Post #5

UtterAccess Member
Posts: 30
From: Barcelona, Spain



All I need is a sample containing a table and a form with its associated controls to populate a treeview and listview control where I can click on its nodes to open a form.
Go to the top of the page
 
+
footbinc
post Oct 22 2003, 10:51 AM
Post #6

UtterAccess Addict
Posts: 125
From: Canada



For the ppictures, you could use the imagelist control. Its a parameter when you are adding nodes to the tree.
Go to the top of the page
 
+
stevomartin
post Oct 23 2003, 09:33 AM
Post #7

New Member
Posts: 8
From: London



Hi

I've managed to modify the code in the Microsoft forum with that of another post in these forums (I forget which post it was and apologies to the person who posted it for not crediting them) to make a data driven tree view that automatically launches a form / report etc.

You'll need a table called OBJECTS with the following fields :

object_id int Primary Key
parent_id number
object_name text (for a form preceed with frm_ , for a table tbl_ etc - you'll see this in the code below)
description text This will appear in the tree control

paste the following into the forms module :

-----------------------------------------------------------

Private Sub Form_Load()

TreeCtrl.Nodes.Clear

'populate the treeview control
Dim db As Database
Dim rs As Recordset
Dim sName As String
Dim sSQL As String

Set db = CurrentDb()
'open table and find the top level object
sSQL = "SELECT * FROM OBJECTS WHERE parent_id = 0"
Set rs = db.OpenRecordset(sSQL, dbOpenDynaset, dbReadOnly)
With rs
.MoveFirst
Do While .EOF = False
TreeCtrl.Nodes.Add , , rs!object_name, rs!description
'add sub levels
AddChildren rs!object_id, rs!object_name
.MoveNext
Loop
End With

'expand all the nodes
For Each Node In TreeCtrl.Nodes
Node.Expanded = True
Next

Set db = Nothing

End Sub

Sub AddChildren(parent_id As Integer, parent_name As String)

Dim db As Database
Dim rs As Recordset
Dim iParentObject As Integer
Dim sParentName As String
Dim sSQL As String

iParentObject = parent_id
sParentName = parent_name
Set db = CurrentDb

'check no of sub objects
If DCount("object_id", "OBJECTS", "parent_id = " & iParentObject) = 0 Then
'no sub objects
Exit Sub
End If

'get sub levels
sSQL = "SELECT * FROM OBJECTS WHERE parent_id = " & iParentObject
Set rs = db.OpenRecordset(sSQL)
With rs
.MoveFirst
Do While .EOF = False
TreeCtrl.Nodes.Add sParentName, tvwChild, rs!object_name, rs!description
AddChildren rs!object_id, rs!object_name
.MoveNext
Loop
End With

rs.Close

End Sub

Private Sub Form_Open(Cancel As Integer)

DoCmd.MoveSize 0, 0

End Sub

Private Sub TreeCtrl_DblClick()

If Left(TreeCtrl.SelectedItem.Key, 4) = "frm_" Then DoCmd.OpenForm TreeCtrl.SelectedItem.Key
If Left(TreeCtrl.SelectedItem.Key, 4) = "rpt_" Then DoCmd.OpenReport TreeCtrl.SelectedItem.Key, acViewPreview
If Left(TreeCtrl.SelectedItem.Key, 4) = "pdf_" Then Application.FollowHyperlink Mid(TreeCtrl.SelectedItem.Key, 5, Len(TreeCtrl.SelectedItem.Key)), , True
If Left(TreeCtrl.SelectedItem.Key, 4) = "doc_" Then Application.FollowHyperlink Mid(TreeCtrl.SelectedItem.Key, 5, Len(TreeCtrl.SelectedItem.Key)), , True
If Left(TreeCtrl.SelectedItem.Key, 4) = "xls_" Then Application.FollowHyperlink Mid(TreeCtrl.SelectedItem.Key, 5, Len(TreeCtrl.SelectedItem.Key)), , True
End Sub

----------------------------------------

I'm sure the code can be optimised but it seems to work OK

Just out of interest : I've been trying to add a key to refer to the image list but when I add an image key at the end of the nodes.add line I get an invalid key. Anybody any ideas?

Kind regards

Steve
Go to the top of the page
 
+
diegorodriguez
post Oct 23 2003, 10:45 AM
Post #8

UtterAccess Member
Posts: 30
From: Barcelona, Spain



Thank you so much for this adaptation. Yes, it comes from the work by Richard Sherwood at

http://www.personal.rdg.ac.uk/~shssherd/databases.htm

Unfortunately (again), it just seems to fail because of unknown reasons. Attached is a small Access 97 treeview.mdb file containing the table objects you suggested and the form including the control tree. May anyone check what was wrong there?

Best regards,

Diego
Attached File(s)
Attached File  treeview.zip ( 33.84K ) Number of downloads: 307
 
Go to the top of the page
 
+
rsewell
post Oct 24 2003, 04:16 PM
Post #9

UtterAccess Enthusiast
Posts: 78
From: Lost in Texas...



Is there anyway to use develop applications that use Treeview without MS Office Developer?
Go to the top of the page
 
+
stevomartin
post Oct 27 2003, 09:02 AM
Post #10

New Member
Posts: 8
From: London



Hi Diego

I'm not sure why the code doesn't work, however, I've made some small changes to get it working (commented out some lines and changed a constant for a number)

Hopefully this should now work for you

Thanks

Steve

-----------------------------------------------------------

Private Sub Form_Load()

TreeCtrl.Nodes.Clear

'populate the treeview control
Dim db As Database
Dim rs As Recordset
Dim sName As String
Dim sSQL As String

Set db = CurrentDb()
'open table and find the top level object
sSQL = "SELECT * FROM OBJECTS WHERE parent_id is null"
Set rs = db.OpenRecordset(sSQL, dbOpenDynaset, dbReadOnly)
With rs
.MoveFirst
Do While .EOF = False
TreeCtrl.Nodes.Add , , rs!object_name, rs!Description
'add sub levels
AddChildren rs!object_id, rs!object_name
.MoveNext
Loop
End With

'expand all the nodes
'For Each Node In TreeCtrl.Nodes
'Node.Expanded = True
'Next

Set db = Nothing

End Sub

Sub AddChildren(parent_id As Integer, parent_name As String)

Dim db As Database
Dim rs As Recordset
Dim iParentObject As Integer
Dim sParentName As String
Dim sSQL As String

iParentObject = parent_id
sParentName = parent_name
Set db = CurrentDb

'check no of sub objects
If DCount("object_id", "OBJECTS", "parent_id = " & iParentObject) = 0 Then
'no sub objects
Exit Sub
End If

'get sub levels
sSQL = "SELECT * FROM OBJECTS WHERE parent_id = " & iParentObject
Set rs = db.OpenRecordset(sSQL)
With rs
.MoveFirst
Do While .EOF = False
TreeCtrl.Nodes.Add sParentName, 4, rs!object_name, rs!Description
AddChildren rs!object_id, rs!object_name
.MoveNext
Loop
End With

rs.Close

End Sub
Go to the top of the page
 
+
diegorodriguez
post Oct 27 2003, 10:54 AM
Post #11

UtterAccess Member
Posts: 30
From: Barcelona, Spain



Thank you very much for this new version of your code: works just perfecly.

I'm now working on the ImageList control to add nice and meaningful icons. Any design hint for that?

Diego
Go to the top of the page
 
+
stevomartin
post Oct 28 2003, 05:14 AM
Post #12

New Member
Posts: 8
From: London



I couldn't get the images to display - I keep on getting Invalid Key Error when I added the image list key to the end of the statement that adds the node. If you get it to work I'd be very keen to know how you did it.

As for icons : try this website : http://www.vbaccelerator.com/home/Resource..._Library/Icons/

Regards

Steve
Go to the top of the page
 
+
diegorodriguez
post Oct 28 2003, 06:32 AM
Post #13

UtterAccess Member
Posts: 30
From: Barcelona, Spain



To add images to your treeview you should do the following:

1 - Add an ImageListCtrl to the same form where the Treeview control is.
2 - Make sure treeview ImageList property is pointing to the same ImageListCtrl name you just set up before on step 1.
3 - On ImageList, browse and add images. You do not need to care on Keys or Tags. Every image is generating a unique index number (1, 2, 3...) you may refer to later on your addNode line.

You may download the atached treeview.mdb for a sample of what has been done so far, including Steve's code.

Now, I know changing background color for an ActiveX control is hard. But, does anyone know an easy way to do it?

Regards,

Diego
Attached File(s)
Attached File  treeview.zip ( 26.08K ) Number of downloads: 537
 
Go to the top of the page
 
+
JayNoelOlimpo
post Nov 10 2003, 08:42 PM
Post #14

UtterAccess VIP
Posts: 7,990
From: Philippines



hi. i'm new at this tree view control could you help me bout treeview and edit the records in the tree view.
Go to the top of the page
 
+
JayNoelOlimpo
post Nov 10 2003, 08:44 PM
Post #15

UtterAccess VIP
Posts: 7,990
From: Philippines



cool thanks for the attachment.
Go to the top of the page
 
+
ghubbell
post Nov 11 2003, 10:42 AM
Post #16

UA Administrator
Posts: 3,441
From: Canada



Have you had any luck with this? I certainly have not...

Gord
Go to the top of the page
 
+
diegorodriguez
post Dec 29 2004, 02:23 PM
Post #17

UtterAccess Member
Posts: 30
From: Barcelona, Spain



Hello again Steve!

Your TreeCtrl code has been working pretty nice, and looks like only one small refinement away from PERFECT.

When I open the form, the tree opens itself to show the 1st branch developed ALWAYS. And I don't want that. I would just want the parents, no children visible until any of the parents are clicked.

Could anyone take a look at the code?


Edited by: diegorodriguez on Wed Dec 29 14:33:33 EST 2004.

Edited by: diegorodriguez on Wed Dec 29 14:34:43 EST 2004.
Go to the top of the page
 
+
richm59
post Dec 29 2004, 03:20 PM
Post #18

UtterAccess Addict
Posts: 120
From: IL



Hi,

(
First of all, add a reference to MSComCTL.OCX (in the System32 directory)
Then add the following code for referencing the treeview

Dim TV As MSComctlLib.treeview
Set TV = TreeCtrl.Object
TV.Nodes.Clear 'used like this - you get intellisense!!!
)

Second, you have SingleSel set to true; set it to false, and your worries are over
TV.SingleSel=False; or set it in the property sheet

Or, if you like SingleSel, you can just close the tree in code:
TV.Nodes(1).Expanded = False

HTH,

Rich
Go to the top of the page
 
+
diegorodriguez
post Dec 30 2004, 08:31 AM
Post #19

UtterAccess Member
Posts: 30
From: Barcelona, Spain



Okay, now looks just perfect! Many thans, Rich
Go to the top of the page
 
+
richm59
post Dec 30 2004, 09:16 AM
Post #20

UtterAccess Addict
Posts: 120
From: IL



QUOTE
Now, I know changing background color for an ActiveX control is hard. But, does anyone know an easy way to do it?

Have you had any luck with this? I certainly have not...


I have been able to do this for controls that are not built into Access. Access controls are not normal - they often do not exist as true windows, so they can't be subclassed, and can't usually receive Windows messages.

If there are any requests, I will try to put together a demo showing how to change the back color of a treeview. But it will take me some time. It's fairly involved, using a number of API calls, and working around some strange painting and refreshing behavior in the treeview control. But it does work well. BTW, you can change many parts of a treeview, if you are willing to spend the time with low-kevel Windows messages. You can change the checkboxes, overlay pictures, manipulate tooltips, etc, etc.

There are a number of web sites out there that show you how to do all of these things (especially MSDN) - but they often require significant code tweaks to get them to work properly in Access.

Rich
Go to the top of the page
 
+

3 Pages V   1 2 3 >
Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 21st May 2013 - 02:01 AM