Treeview nodelevel (2 Viewers)

ClaraBarton

Registered User.
Local time
Yesterday, 16:32
Joined
Oct 14, 2019
Messages
715
@MajP So I'm combining your ItemGenie with my own thing and getting all fancy and such... and I added fields to the application settings and created more formatting:
1756409768015.png

(the orange fields will be hidden) . But when I got to the format treeview I realized there is no tvw property for nodelevel. What else would I use for the different levels? Or am I way off on the wrong track? I wanted more than just locations and items.
 
In the version I was demoing for @dalski it has a table where you can define the colors for the different levels and/or types of nodes.
In his version certain nodes can be at certain levels, but are of a specific type like a comment, or bill item. These always have a specific color. Headers can be at multiple levels and have a different color per level.

There is a default table where you can pick the forecolor and back color for nodes at a specific level.
levelEdit.PNG


1. To format you loop all the nodes
In this case there are different colors depending on the "Type" of node and on its level.

2. Determine type (SB, H,Billitem, Comment) . I store that in the tvw Node identifier property
3. If it is a "header" you determine level.
You determine a nodes level from the method
Code:
tvw.GetNodeLevel(nd)
Where ND is a node found from looping all the nodes.
3. Once you know the type and level you can use a dlookup to get the colors and format.

I attached the form because it has a color picker and some nice features.

This then does something like this.
Level Colors.PNG
 

Attachments

Well, I'm definitely incorporating that into my program! :love:But, same problem. My identifiers are Location and Item. How do I tell my treeview that I want to format by level? All of your identifiers are different but mine aren't. Location has at least 3 levels.
The levels change when moving so it seems like that is where the format rule should be.
 
Can you concatenate LocationID-ItemID as the identifier? That would be unique, no?
 
Last edited:
All of your identifiers are different but mine aren't. My identifiers are Location and Item. How do I tell my treeview that I want to format by level? All of your identifiers are different but mine aren't. Location has at least 3 levels.
That is not true there are multiple levels of headers shown. I can have formatting up to 8 levels of headers. Headers are formatted by level. As I said you determine if it is a header and then you use the level to determine the formatting. The other items SB, Comment, Bill item get a constant format.

The headers can have up to 8 levels of formatting. There are two levels shown
2.1 is a header at the first level of headers Blue
2.1.1 is a header at the second level of headers. Green
 
here is the function to return the colors. I pass in the nodelevel determined from the tvw.getNodeLevel and the node type determined from the tvw.getNodeIdentifier. For headers the node level matters.

Code:
Public Function GetNodeColor(NodeLevel As Integer, nodekey As String, BillID As Long) As Long
  Dim nt As String
  Dim SubBill As Boolean
  SubBill = HasSubBill(BillID)
  Dim GetNodeItalicYesNo As Boolean
  'Debug.Print SubBill
  nt = GetNodeType(nodekey)
  'Debug.Print NT
  Select Case nt
  Case "C"
     GetNodeColor = Nz(DLookup("HeaderColor", "HeaderTypesT", "TypeIdentifier = 'C'"), 0)
  Case "BI"
     GetNodeColor = Nz(DLookup("HeaderColor", "HeaderTypesT", "TypeIdentifier = 'BI'"), 0)
  Case "SB"
      GetNodeColor = Nz(DLookup("HeaderColor", "HeaderTypesT", "TypeIdentifier = 'SB'"), 0)
  Case "H"
    'if the bill is composed of subbills then a node on second level is the first H level
    If SubBill Then NodeLevel = NodeLevel - 1
    GetNodeColor = Nz(DLookup("HeaderColor", "HeaderTypesT", "TypeIdentifier = 'H' and HeaderLevel = " & NodeLevel), 0)
  End Select
End Function
 
Here is image with more header levels

Level Colors.PNG


Here is more of the format code
Code:
Public Sub FormatNodes()
  Dim nd As Node
  For Each nd In tvw.Nodes
   FormatNode nd
  Next nd
End Sub

'
Public Sub FormatNode(nd As Node)
  If nd.Tag = "Header_" Then
      FormatHeader nd
    ElseIf nd.Tag = "BillItem_" Then
      FormatBillItem nd
    End If
End Sub

Public Sub FormatBillItem(nd As Node)
  With nd
    .BackColor = Nz(Me.ItemBackColor, vbWhite)
    .ForeColor = GetNodeColor(1, nd.Key, Me.BillID)
    '.Bold = False
  End With
End Sub

Public Sub FormatHeader(nd As Node)
  With nd
    '.BackColor = Nz(Me.HeaderBackColor, vbWhite)
    ' Debug.Print "color " & GetNodeColor(tvw.GetNodeLevel(nd), nd.Key, Me.BillID)
     .ForeColor = GetNodeColor(tvw.GetNodeLevel(nd), nd.Key, Me.BillID)
    '.Bold = True
  End With
End Sub
 
I love your pictures. I get it. But notice your're using "nt" for nodetype.. case C, BI, SB.
GetNodeLevel returns a key. I thought I understood the levels but you don't use them the way it seems like you should.
Even the tag uses the node PK.
I'm not being intentionally oblique... just missing something. sorry
It LOOKS like the coloring is for nodelevel but that isn't reflected in the code... is it?
 
Can you concatenate LocationID-ItemID as the identifier? That would be unique, no?
I'm not really looking for unique... I'm looking for the various levels. And when the level changes, as in moves or gets descendants or whatever, the formatting should go with the level, not the item.
 
I love your pictures. I get it. But notice your're using "nt" for nodetype.. case C, BI, SB.
GetNodeLevel returns a key. I thought I understood the levels but you don't use them the way it seems like you should.
Even the tag uses the node PK.
I'm not being intentionally oblique... just missing something. sorry
It LOOKS like the coloring is for nodelevel but that isn't reflected in the code... is it?
I am completely lost. I am showing an image that is 7 levels deep of "headers". Each level has different formatting based on the header level.
The tag tells me what type SB, Bill Item, Comment, or Header
The node level tells me what level.
For headers I use the level in addition to the type. Not sure how else that image is possible. Other types do not use the level they get the same format regardless of level

Code:
  Case "H"
    'if the bill is composed of subbills then a node on second level is the first H level
    If SubBill Then NodeLevel = NodeLevel - 1
    GetNodeColor = Nz(DLookup("HeaderColor", "HeaderTypesT", "TypeIdentifier = 'H' and HeaderLevel = " & NodeLevel), 0)
.
 
1756426342042.png

Here are my loctions... all headers. But headers on level 2 and level 3 should be different than level 1.
1756426478134.png

Here are my levels. Now what?
Code:
Public Sub FormatTree()
    With tvw.TreeView
        .Font.Size = Me.FontSize
        .Font.Name = Me.FontName
        .Indentation = 150
    End With
End Sub
Public Sub FormatNodes()
  Dim nd As Node
  For Each nd In tvw.Nodes
   FormatNode nd
  Next nd
End Sub


Public Sub FormatItem(nd As Node)
  With nd
    .BackColor = Nz(Me.ItemBackColor, vbWhite)
    .ForeColor = Nz(Me.ItemForeColor, vbBlack)
    .bold = Me.ItemBold
  End With
End Sub
Public Sub FormatLocation(nd As Node)
  With nd
    .BackColor = Nz(Me.LocationBackColor, vbWhite)
    .ForeColor = Nz(Me.LocationForeColor, vbBlack)
    .bold = Me.LocationBold
  End With
End Sub
 
If this is mirroring ItemGenie then Locations can be nested (a box can be inside a cabinet that can be inside the garage). Items cannot be nested or at least that was how it was designed (cannot do fuel tank inside of lawnmower).

1. Determine if it is a location or an item. If item all items are formatted the same. Use the identifier property to determine node type. The Identifier is a wrapper around the tag property of the node.
2. If the node is a Location use the getnodelevel to determine the level
3. Either hard wire the format based on level or pull the format from the table by creating a function to do a dlookup by level.
 

Users who are viewing this thread

  • Back
    Top Bottom