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 Jan 9 2005, 06:12 AM
Post #21

UtterAccess Member
Posts: 30
From: Barcelona, Spain



In the example above, everything works properly, but the displayed order of parent folders and children objects doesn't seem to follow any simple rule (alphabetical, order of appearance in the object table, etc...).

Is there anything in the associated code or control properties controlling this display order?
Go to the top of the page
 
+
richm59
post Jan 9 2005, 12:56 PM
Post #22

UtterAccess Addict
Posts: 120
From: IL



The treeview nodes occur in the order that they were added.
During the addition of nodes, you can specify where the new node is added by using the treeview enumerated constants (TreeRelationshipConstants) like:

tvwChild
tvwFirst
tvwLast
tvwNext
tvwPrevious

These constants are used in relation to another "Relative" node:

Tvw1.Nodes.Add "RelativeNodeKey", tvwChild, "KeyText","LabelText"

All of this is detailed in the Treeview help file, and in the online docs at MSDN.com:
http://msdn.microsoft.com/library/default....objtreeview.asp

HTH
Rich
Go to the top of the page
 
+
louzam2115
post Jan 11 2005, 11:42 AM
Post #23

UtterAccess Addict
Posts: 234



Neat, I like it, I wish I could use it in my database but I have no use for a tree control, maybe I will think of one.
Go to the top of the page
 
+
mmsayed
post Jan 12 2005, 12:10 PM
Post #24

UtterAccess Guru
Posts: 805
From: United States



Gord,

You can change the background color of the treeveiw. I found the following code on
http://www.msfn.org/board/index.php?showto...4&st=0&
*******************************************************
Option Explicit 'Needed to make sure declared strings etc work
Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long 'Used to set the following tweak
Private Declare Function GetWindowLong Lib "User32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long 'Get treeview handle
Private Declare Function SetWindowLong Lib "User32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long 'Set handle
Private Const GWL_STYLE = -16& 'The current style of treeview
Private Const TVM_SETBKCOLOR = 4381& 'Set Bground Color
Private Const TVM_GETBKCOLOR = 4383& "Get Bground Color
Private Const TVS_HASLINES = 2& 'Misc stuff needed
Dim frmlastForm As Form 'The form using

Private Sub Form_Load()
Dim nodX As Node 'Creates nodX as the default Node
Set nodX = TreeView1.Nodes.Add(, , "R", "Default Plugins") 'Cut all this out of a prog i doing currently (IMG:http://www.utteraccess.com/forum/style_emoticons/default/tongue.gif)
Set nodX = TreeView1.Nodes.Add("R", tvwChild, "DP1", "Bios")
Set nodX = TreeView1.Nodes.Add("R", tvwChild, "DP2", "Video")
Set nodX = TreeView1.Nodes.Add("R", tvwChild, "DP3", "Sound")
Set nodX = TreeView1.Nodes.Add("R", tvwChild, "DP4", "CD/DVD")
Set nodX = TreeView1.Nodes.Add("R", tvwChild, "DP5", "Controllers")
nodX.EnsureVisible ' Make sure it visible
TreeView1.Style = tvwTreelinesText ' Style 4.
TreeView1.BorderStyle = vbFixedSingle
ChangeTreeviewColor 'This will be eventually the event to change the color (IMG:http://www.utteraccess.com/forum/style_emoticons/default/frown.gif)
End Sub


Private Sub ChangeTreeviewColor()
Dim lngStyle As Long 'Explained further on
Call SendMessage(TreeView1.hWnd, TVM_SETBKCOLOR, 0, ByVal RGB(216, 228, 248)) 'Sends a message setting the color defined in the RGB(x,x,x) color value
lngStyle = GetWindowLong(TreeView1.hWnd, GWL_STYLE) 'lngStyle will have the init handle of treeview control
Call SetWindowLong(TreeView1.hWnd, GWL_STYLE, lngStyle - TVS_HASLINES) 'Sets handle
Call SetWindowLong(TreeView1.hWnd, GWL_STYLE, lngStyle) 'Sets handle
End Sub
*****************************************************************

I tweaked the code a bit and was able to replicate the same thing with alot less code. Here is my version:

Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long 'Used to set the following tweak
Private Const TVM_SETBKCOLOR = 4381& 'Set Bground Color
Private Const TVM_GETBKCOLOR = 4383& 'Get Bground Color

'Call this function in form load event
Private Sub ChangeTreeviewColor()
Call SendMessage(tvwMIS.hWnd, TVM_SETBKCOLOR, 0, ByVal (16764057))
End Sub

HTH,
Mehdi (IMG:http://www.utteraccess.com/forum/style_emoticons/default/frown.gif)
Go to the top of the page
 
+
richm59
post Jan 12 2005, 12:25 PM
Post #25

UtterAccess Addict
Posts: 120
From: IL



QUOTE
Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long 'Used to set the following tweak
Private Const TVM_SETBKCOLOR = 4381& 'Set Bground Color
Private Const TVM_GETBKCOLOR = 4383& 'Get Bground Color

'Call this function in form load event
Private Sub ChangeTreeviewColor()
Call SendMessage(tvwMIS.hWnd, TVM_SETBKCOLOR, 0, ByVal (16764057))
End Sub


I have been used this technique as well, but it my hands, I also have to change the BackColor of each node to match the Treeview background. Not a problem really, but it helps to know about it.

Rich
Go to the top of the page
 
+
mmsayed
post Jan 12 2005, 01:06 PM
Post #26

UtterAccess Guru
Posts: 805
From: United States



I'm sorry you are correct. I was going to mention it but forgot.

**To change the backcolor of an image you will have to do this:**
Right click the ImageListCtrl >> ImageListCtrl Object >> Properties >> select "Color" tab>> change the color to match your background color.

**As Rich stated to change the backcolor of a node you will have to do something like this :**
node.backcolor=1234564584

Thanks and HTH (IMG:http://www.utteraccess.com/forum/style_emoticons/default/frown.gif)
Mehdi

Edited by: mmsayed on Wed Jan 12 13:38:24 EST 2005.
Go to the top of the page
 
+
richm59
post Jan 13 2005, 02:43 PM
Post #27

UtterAccess Addict
Posts: 120
From: IL



Hi Mehdi,

Thanks for the tip about the Image Control Background color. It fixes an old problem for me!

Rich

Edited by: richm59 on Thu Jan 13 14:52:29 EST 2005.
Go to the top of the page
 
+
mmsayed
post Jan 13 2005, 04:59 PM
Post #28

UtterAccess Guru
Posts: 805
From: United States



Not a problem, glad to help (with atleast one issue)!

Mehdi (IMG:http://www.utteraccess.com/forum/style_emoticons/default/frown.gif)
Go to the top of the page
 
+
mmsayed
post Jan 26 2005, 09:42 AM
Post #29

UtterAccess Guru
Posts: 805
From: United States



Just a side note to color the Node you need to declare it as an object and then do the backcolor thing:

Dim objCurrNode as Object

objCurrNode.backcolor=16764057

I usually just add this line in my loop as I am building the tree.

HTH,
Mehdi
Go to the top of the page
 
+
linhqhta
post Aug 22 2008, 03:44 AM
Post #30

New Member
Posts: 1



thanks for posted!
Go to the top of the page
 
+
williams9969
post Sep 9 2008, 03:34 PM
Post #31

UtterAccess Ruler
Posts: 1,888
From: US Army / Iraq



I really like this treeview but am limited to only three icons.

I would like to be able to apply many different icons...any ideas?

Thanks!!!!!!!!
Go to the top of the page
 
+
williams9969
post Sep 10 2008, 03:27 PM
Post #32

UtterAccess Ruler
Posts: 1,888
From: US Army / Iraq



Noone has a working example of a treeview with different ICONS on it? I truely
want to use this as a menu for my upcoming DB...please help.

thanks!!!!!!!!!!!!!!!!
Go to the top of the page
 
+
Clippit
post Sep 11 2008, 09:26 PM
Post #33

UtterAccess VIP
Posts: 3,645
From: Near Toronto, ON, CA



I don't have a working example handy with several icons but have done this in the past. It's just a matter of adding more images to your ImageList control and then in the code that fills the treeview determining which icons applies to each node. If you have three now it should be easy to add more.
Go to the top of the page
 
+
williams9969
post Sep 13 2008, 10:17 AM
Post #34

UtterAccess Ruler
Posts: 1,888
From: US Army / Iraq



Thanks for the reply.

I assumed it would be too...but cannot figure it out. I have tried
for awhile now...applying different options to the code(s) above....but no luck

Any ideas on what to do to it?

Thanks again for the help!
Go to the top of the page
 
+
Clippit
post Sep 13 2008, 10:22 AM
Post #35

UtterAccess VIP
Posts: 3,645
From: Near Toronto, ON, CA



Have you added a new image to the imagelist?

What's your code for adding nodes to the treeview?
Go to the top of the page
 
+
williams9969
post Sep 13 2008, 12:22 PM
Post #36

UtterAccess Ruler
Posts: 1,888
From: US Army / Iraq



Here is the code I am using...same as above...

CODE
  

Option Compare Database

Option Explicit



Private Sub Form_Load()

Dim TV As MSComctlLib.treeview

Dim db As Database

Dim rs As Recordset

Dim sName As String

Dim sSQL As String

Dim Cap As String



TreeCtrl.Nodes.Clear



'populate the treeview control



Set TV = TreeCtrl.Object



TV.Nodes.Clear 'used like this - you get intellisense!!!



TV.SingleSel = False



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, 1, 2

'add sub levels

AddChildren rs!object_id, rs!object_name

.MoveNext

Loop

End With



'Call this function in form load event

'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, 3

'******************************************************************************

AddChildren rs!object_id, rs!object_name

.MoveNext

Loop

End With



rs.Close



End Sub


The problem I am having is using more then 3 icons...

I want to be able to add an icon specific to what are is on the treeview...not just one icon for the parent inactive,
then one active...then a different icon for the child

I have about 9 sections(plus) that I want to be able to apply different icons to.

Thanks for the interest and the help!!!




Edited by: williams9969 on Sat Sep 13 13:22:49 EDT 2008.
Go to the top of the page
 
+
williams9969
post Sep 13 2008, 12:29 PM
Post #37

UtterAccess Ruler
Posts: 1,888
From: US Army / Iraq



Oh...sorry for not answering part of ??

Yes, I have loaded about 10 icons...trying to find a way

Thanks again!
Go to the top of the page
 
+
Clippit
post Sep 13 2008, 01:08 PM
Post #38

UtterAccess VIP
Posts: 3,645
From: Near Toronto, ON, CA



You need to figure out how to determine in your code what icon (by index number) applies to your node, and then specify that index number instead of the 3 that you're using now when you add a child. (The last parameter on the Nodes.Add statement.)

What do the other icons mean? How will Access know from your data which icon applies?
Go to the top of the page
 
+
williams9969
post Sep 13 2008, 01:15 PM
Post #39

UtterAccess Ruler
Posts: 1,888
From: US Army / Iraq



Steve-

Thanks for the help....I have been trying to figure that part out....

I am a VBA novice and don't know really how to apply this.

I appreciate the help and I will keep pounding away at it.

Thanks again!!!
Go to the top of the page
 
+
Clippit
post Sep 13 2008, 06:09 PM
Post #40

UtterAccess VIP
Posts: 3,645
From: Near Toronto, ON, CA



Sounds good.
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:23 PM